Adding Log In/Out Links

After figuring out how to change the “site-info” in the Understrap theme I decided to add log in and log out buttons.

These visible based on if the user is already logged in or not.

It also dynamically gets the site url so that this code can be reused on sites with little changed.

To do this simply add the following code to “functions.php” of your child theme:

/**
 * Changes "site-info" to our boilerplate copyright.
 * Also adds Log In and Log Out links.
 */
function remove_parent_functions() {
    remove_action( 'understrap_site_info', 'understrap_add_site_info' );
    add_action( 'understrap_site_info', 'understrap_add_site_child_info' );
}
add_action( 'init', 'remove_parent_functions', 15 );
function understrap_add_site_child_info() {
	
	if(is_user_logged_in()) {
		?>
    <div class="wrap"><p>Site commissioned from Tees Valley Arts &nbsp; ⁄ &nbsp; Copyright ©&nbsp;2021 &nbsp; ⁄ &nbsp; <a rel="nofollow" href=<?php echo get_site_url().'/wp-login.php?action=logout&amp;_wpnonce=5969d1c9bc' ?>>Log out</a></p></div>
    <?php
	} else {
		?>

    <div class="wrap"><p>Site commissioned from Tees Valley Arts &nbsp; ⁄ &nbsp; Copyright ©&nbsp;2021 &nbsp; ⁄ &nbsp; <a rel="nofollow" href=<?php echo get_site_url().'/wp-login.php' ?>>Log in</a></p></div>
    <?php
	}
}

Filed under: WordPressTagged with: , , ,

No comment yet, add your voice below!


Add a Comment

Your email address will not be published. Required fields are marked *

Comment *
Name *
Email *
Website