• What is TechTraction?

    Personal commentary on technology with a sprinkling of tech-tips and how-to articles

Dynamically Display Sidebar Meta Links in Your WordPress Theme

Look at any free WordPress themes and you’ll notice that most of them have a “Meta” section in the sidebar. Options to login, logout, or jump to the WordPress Dashboard are often found in this section. And while the links are convenient for the owner of the site, they are only useful to that individual. Wouldn’t it be great to dynamically display standard meta links to only those people that could use them? Fortunately, with a little theme modification you can do just that, and here is how.

Dynamic Meta Links Require Login First

Hiding useful sidebar meta links is easy, but it does require that you (or any other user authorized to access the site) log into your site first. There is no way to dynamically display the meta links unless the under laying system (in this case, WordPress) knows who is looking at a page. Therefore, dynamic link display works when you, or other authorized user, first visits, and logs into, the standard WordPress login page: http://<your domain>/wp-login.php

Standard Meta PHP Code

Most sidebars use the following code to display the meta links:

<h2><?php _e('Meta'); ?></h2>
<?php wp_register(); ?>
<?php wp_loginout(); ?>

The links are useful but only to authorized WordPress users for this site. To make the meta section dynamically appear, simply enclose it an “if statement” that tests to see whether the current user is logged using the function is_user_logged_in(). Once the “if statement” is created the previously shown meta section looks like this:

<? php if(is_user_logged_in()) {

<h2><?php _e('Meta'); ?></h2>
<?php wp_register(); ?>
<?php wp_loginout(); ?>

}

You might need to tweak the above code to get exactly what you want, but it will do the trick.

As another example, here is what I am using on a new theme I am working on:

<?php if(is_user_logged_in()) {
echo '<li><h2>TechTraction Staff Only</h2><ul>';
wp_register();
wp_loginout();
echo '</ul></li>';
} ?>

Hiding Meta Links is Not a Form of Security

One simple change and the meta links appear once I’m logged in and don’t display for anyone else. Keep in mind, hiding meta links such as wp_loginout() is NOT a form of security. As everyone should know, security through obscurity is useless.

Hiding meta links is just a way to reclaim sidebar real estate which can be used for something more meaningful for the average site visitor.


If you liked this post, subscribe to TechTraction's RSS feed or TechTraction's email feed

Filed under: How-To & Tech Tips

One Response to “Dynamically Display Sidebar Meta Links in Your WordPress Theme”

  1. Wow, nice thanks for the info

Leave a Reply