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!

Leave a Reply

Privacy & more..

Cookie Consent Policy