- This topic has 6 replies, 2 voices, and was last updated 8 years, 10 months ago by Mahesh.
-
AuthorPosts
-
February 10, 2016 at 3:25 am #85053andrewf90Member
Hi,
I was wondering how I might add the login/logout php script so that it falls in the second footer widget column in line with the rest of the links in that column?
I tried stuffing the following script in the footer.php file just to see where it ends up, but no luck. It ends up in its own container or space in the footer.
Any ideas?
Thanks 😛
<?php if (is_user_logged_in()) : ?> <a href="<?php echo wp_logout_url(get_permalink()); ?>">logout | </a> <?php else : ?> <a href="<?php echo wp_login_url(get_permalink()); ?>">login | </a> <?php endif;?>
February 10, 2016 at 12:49 pm #85073MaheshParticipantHi @andrewf90,
You need to create a child theme for this. You can find more details on creating a child theme HERE. Then your child theme’s
functions.php
add the following code.function catchflames_child_adjust_footer_two_widget(){ //Footer Two Sidebar register_sidebar( array( 'name' => __( 'Footer Area Two', 'catch-flames' ), 'id' => 'sidebar-3', 'description' => __( 'An optional widget area for your site footer', 'catch-flames' ), 'before_widget' => '<aside id="%1$s" class="widget %2$s">', //'after_widget' => "</aside>", 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ) ); } add_action( 'init', 'catchflames_child_adjust_footer_two_widget' );
Then create a file in you child theme’s folder and name it
sidebar-footer.php
and the following codes:<?php /** * The Footer widget areas. * * @package Catch Themes * @subpackage Catch Flames * @since Catch Flames 1.0 */ ?> <?php /* The footer widget area is triggered if any of the areas * have widgets. So let's check that first. * * If none of the sidebars have widgets, then let's bail early. */ if ( ! is_active_sidebar( 'sidebar-2' ) && ! is_active_sidebar( 'sidebar-3' ) && ! is_active_sidebar( 'sidebar-4' ) ) return; // If we get this far, we have widgets. Let do this. ?> <?php /** * catchflames_before_footer_sidebar hook */ do_action( 'catchflames_before_footer_sidebar' ); ?> <div id="footer-sidebar"> <div id="supplementary" <?php catchflames_footer_sidebar_class(); ?>> <div class="wrapper"> <?php if ( is_active_sidebar( 'sidebar-2' ) ) : ?> <div id="first" class="widget-area" role="complementary"> <?php dynamic_sidebar( 'sidebar-2' ); ?> </div><!-- #first .widget-area --> <?php endif; ?> <?php if ( is_active_sidebar( 'sidebar-3' ) ) : ?> <div id="second" class="widget-area" role="complementary"> <?php dynamic_sidebar( 'sidebar-3' ); ?> <?php if (is_user_logged_in()) : ?> <a href="<?php echo wp_logout_url(get_permalink()); ?>">logout | </a> <?php else : ?> <a href="<?php echo wp_login_url(get_permalink()); ?>">login | </a> <?php endif;?> </aside> </div><!-- #second .widget-area --> <?php endif; ?> <?php if ( is_active_sidebar( 'sidebar-4' ) ) : ?> <div id="third" class="widget-area" role="complementary"> <?php dynamic_sidebar( 'sidebar-4' ); ?> </div><!-- #third .widget-area --> <?php endif; ?> </div><!-- .wrapper --> </div><!-- #supplementary --> </div><!-- #footer-sidebar --> <?php /** * catchflames_after_footer_sidebar hook */ do_action( 'catchflames_after_footer_sidebar' ); ?>
Regards,
MaheshFebruary 10, 2016 at 1:09 pm #85076andrewf90MemberHey, again! 😛
So I downloaded the child theme sample and I copied the first code snippet to the
functions.php
file and created the second file and inserted the second code snippet, but it looks like the footer area stayed the same. What might I be doing wrong? Sorry for the trouble.February 10, 2016 at 1:27 pm #85079MaheshParticipantHi @andrewf90,
The code is working fine on our server (localhost). Have you activated the child theme? 🙂
Regards,
MaheshFebruary 10, 2016 at 1:52 pm #85085andrewf90MemberLol, I didn’t realize I had to do that. So the child theme is placed in its own parent folder in the /theme/ folder. When I activate it, my site doesn’t load, so I have to deactivate the child theme by changing its file name. Any idea what I might be doing wrong?
February 10, 2016 at 2:26 pm #85087andrewf90MemberOnce again, I did something wrong. I created the folder myself and I uploaded two files. I ended up deleting that and then following the Upload Theme option through the WordPress dashboard, and voilà! It worked. I went back to the child theme folder and I noticed there were four files in total? I only uploaded the
functions.php
and.css
files. Oh my. So, it all works. Thanks a bunch!February 10, 2016 at 2:35 pm #85089MaheshParticipantHi @andrewf90,
Oh that’s great.
Glad to know that you’ve managed to make it work now.Regards,
Mahesh -
AuthorPosts
- The topic ‘Adding Login/Logout Links to Footer’ is closed to new replies.