Here’s handy php function which will place a log in / log out link any where you place the function call in a wordpress blog. It’s split into three parts.
Firstly the function which does the work, then the function call, and finally the css.

Here’s the php code for the function.
Paste it into the functions.php file in your current theme directory.

function wordpress_login_link() {
	if ( is_user_logged_in() ) {
		$logoutlnk = wp_logout_url(home_url());
		echo '<span class="footlink"><a href="'.$logoutlnk.'">Log Out</a></span>';
	} else {
		echo '<span class="footlink"><a href="./wordpress/wp-login.php">Log In</a></span>';

Below is the function call which can be copied into virtually any of the php page templates in your theme directory depending on where you want your link to appear. Footer.php for example

<?php wordpress_login_link(); ?>

And finally add the css text into style.css to format your link nicely, this is just an example and you will probably want to adjust the css (and remove the padding) to enable it to match your site!

.footlink {padding-left: 5px;}
.footlink a {color: #333;}
.footlink a:hover {color: orange;}

Let me know if you use it!

Latest Posts



Fill in the form below to send us a message. Your details will not be used for promotional purposes or passed on to any third parties.


By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.