Free Wordpress Help | Wordpress Themes - Removing Unwanted Sections From The Sidebar

Ask me a question at the Wordpress Ninja Forum

 

Wordpress Themes - Removing Unwanted Sections From The Sidebar

Posted on July 2, 2008
Filed Under Wordpress Solutions |

I’m going to digress from the Beginner’s Guide series for a bit as i received a great question yesterday about editing raw Wordpress Themes and how to remove unwanted sections from the sidebar, in particular sections like Categories, Recently Added, Meta, Blogroll etc.

The answer is fairly simple and involves direct editing of your wordpress theme’s .php files - in particular the file sidebar.php

The example i am going to use is from the fantastic ‘Prosense‘ Wordpress theme, but you’ll find that despite some strange differences, most themes will basically fall into the same boat for this example, despite how unusual the site layout may be.

If you check out my blog on Broadway Musicals you will see it has been heavily modded, which is why i thought it would be a great example for this blog. It actually began as a basic ‘Prosense‘ Wordpress theme would you believe and has been modded to the point where it is almost unrecognizable from it’s original form, showing just how much a bit of modding effort can achieve. Note how several things have been changed in the sidebar compared to the original theme.

Usually one of the first things i do when i start a new blog is to edit the sidebar and get rid of things i dont want, such as the pesky ‘Meta’ links. I remove some things, change wording on other things and add sections in as well.

For this example i am going to remove some sections (’Categories’ and ‘Recent Entries’) from the left side of the sidebar - the Prosense Wordpress theme has a sidebar on the right of the posts area which is divided into 2 parts - left sidebar and right sidebar - though the layout is still classed as 3-column (content and 2 parts of the sidebar form the 3 columns).

So let’s get started. As always, make sure you have backups of all your files before making any changes!

Edit your sidebar.php file located in your wp-content/themes/<your theme name>/ folder - you can use a plain text editor or a html editor - i can really recommend Dreamweaver but that is fairly expensive so have a look for some good freeware code editors (i can recommend the freeware editors Arachnophilia, PHP Eclipse and PSPad - failing all that good old notepad is ok….)

You would need to locate the following code in this file - IMPORTANT - you need to find the section beginning with <div class=”sidebar_left”> - just to explain this, the whole webpage is divided into several sections - a header, a body, a sidebar (which is further divided into a left and right section) and a footer - keep this in mind always when editing - so you would edit the leftmost side of the sidebar, not the rightmost side:

<li><h2>Categories</h2>
<ul>
<?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=1'); ?>
</ul>
</li>

<li><h2>Recent Entries</h2>
<ul>
<?php query_posts('showposts=10'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title() ?></a></li>
<?php endwhile; endif; ?>
</ul>

To explain this, the first paragraph is for the ‘Categories’ section and the second paragraph is the ‘Recent Entries’. Where you see the <h2> tag - that means it is a heading (bolded, bigger font). So to get rid of them from the left sidebar, you just need to delete each of the paragraphs in the sidebar.php file that have headings corresponding to what you want to get rid of. So delete the whole ‘Categories’ code section and the whole ‘Recent Entries’ code section. Then save the file and upload it back to your server, overwriting the old sidebar.php file. That’s it - super easy huh?

How about if i just want to remove all of the links from the ‘Meta’ section except the ‘register’ and ‘login ‘ links? Well, this is easy also….Find the code below - usually in the rightmost sidebar section so you want to find the <div class=”sidebar_right”> division in the code. Under that somewhere you will likely find this code:

<li><h2>Meta</h2>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<li><a href="http://validator.w3.org/check/referer" title="This page validates as XHTML 1.0 Transitional">Valid <abbr title="eXtensible HyperText Markup Language">XHTML</abbr></a></li>
<li><a href="http://gmpg.org/xfn/"><abbr title="XHTML Friends Network">XFN</abbr></a></li>
<li><a href="http://wordpress.org/" title="Powered by WordPress, state-of-the-art semantic personal publishing platform.">WordPress</a></li>
<?php wp_meta(); ?>
</ul>

</li>

What you need to do is delete all the stuff you dont want, leaving just the following code:

<li><h2>Meta</h2>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
</ul>

</li>

This will have the desired output of just showing a heading called ‘Meta’ with the links ‘Register’ and ‘Login’ underneath. You can use these principles to remove any unwanted sections or links from your sidebar. But hang on, i hate the name ‘Meta’ so i will change that to ‘Admin Stuff’ by editing the line:

<li><h2>Meta</h2>

to be:

<li><h2>Admin Stuff</h2>

the <h2> tags refer to the fact that it is a heading of a certain size. Refer to this tutorial site for html headings and other basics.

As always i’ll be happy to answer any issues or questions you may have on any of this, so leave a comment below.

In the coming weeks/months i will cover setting up RSS feeds properly with Feedburner, an in-depth guide to Categories and Pages and their most useful parameters, custom graphics for headers, SEO optimization of your Wordpress Theme and plenty of other useful topics. Subscribe now so you don’t miss anything!

Comments

3 Responses to “Wordpress Themes - Removing Unwanted Sections From The Sidebar”

  1. Adding Google Adsense To A New Wordpress Theme | Wordpress Ninja on August 1st, 2008 6:57 am

    [...] have saved out your code blocks, open your favorite code editing app (i listed several good ones in this post) and start editing your Wordpress files. Now, depending on your desired ad placement, you need to [...]

  2. jamal on November 3rd, 2008 5:11 pm

    Where is the Blogroll entry? I managed to remove all of them except the blogroll. Its not present there.
    Kindly help!!!

  3. coachaviv on November 9th, 2008 1:27 pm

    i can’t find the recent post on my sidebar.php
    here is a link to it on the wordpress forum
    http://wordpress.org/support/topic/216110?replies=1
    any suggestions how to do this?
    Thanks!

Leave a Reply




 

Related Posts: