CrankBerry Blog Title
2009


(14) Comments

Removing bullets from WordPress default theme menu

As I was setting up this blog I was disgusted by the bullets that were implemented to the menu on the right (they call it side bar). I thought to myself, no biggie, I'll just remove it when skinning/theming this thing. As I have built many themes for different forums in the past I believe this wouldn't be such a hard task. After some searching I have found this article, but by editing the CSS it did not work for me. So here I'm sharing a method to hard code out the bullets in the side bar of the default WordPress theme Kubrick.

Now this method is not recommended for those who are not comfortable or disturbed by the thought of "editing code". Its really not all that complicated but if you're really not comfortable stop reading now and quit while you're ahead, I'm sure there's other people out there ready to help.

What will you get from this?

In the end you should be able to successfully remove the bullets in the Pages, Archives, Categories, and Bookmarks inner section. These are what I've named them, yours could vary. I'm calling it the inner section because I didn't talk about how to remove the bullets in the title here, at this point I haven't gone through everything so I'll update every one when it happens.

So, with that said lets get started. Here is a list of files that we'll be editing so I recommend you make a backup prior to beginning just in case something goes wrong.

  • wp-includes/classes.php
  • wp-content/themes/default/sidebar.php
  • wp-includes/bookmark-template.php

Got that? Backed it up? Good! We'll start from the top, so the first bullets we'll remove is the Pages section. These are links to pages that you can create outside of your blog postings.

Removing Bullets from the Pages Section

Open wp-includes/classes.php, if your editor has a find function use it now. Find the line class Walker_Page. This is the class that we need to work in.

function start_lvl(&$output, $depth) {
        $indent = str_repeat("\t", $depth);
        $output .= "\n$indent<ul>\n";
}

In line 3 you can find the <ul> we need to remove. So remove it. Now the we removed the opening tag we have to remove the closing tag. Scroll down a little bit and the closing tag is on line 3 of:

function end_lvl(&$output, $depth) {
        $indent = str_repeat("\t", $depth);
        $output .= "$indent</ul>\n";
}

Ok, now stay where you are. Scroll down a little more and you'll come across the function start_el. Within the function look for a line that looks or is exactly like:

$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) . '" title="' . esc_attr(apply_filters('the_title', $page->post_title)) . '">' . $link_before . apply_filters('the_title', $page->post_title) . $link_after . '</a>';

In this code here you'll have to remove the following code. Note: Don't remove the ' in the beginning.

<li class="' . $css_class . '">

What we just did was remove the opening <li> lets find and remove the closing one. Take a guess at where it is, you're right! Scroll down a little more and you'll find the missing piece of the puzzle. Within the func end_el you'll notice the </li> in line two.

function end_el(&$output, $page, $depth) {
        $output .= "</li>\n";
}

Instead of just removing this one, replace it with <br />. This will add a line break between page listing.

Removing Bullets from the Category Section

At this point you should have already removed the bullets for the page section. Has it happened? If not you should spend some time in the first part of the article first. Next we will work on the category section, so in the same file find:

<?php wp_list_categories('show_count=1&title_li=<h2>Categories</h2>'); ?>

and change that to

<?php wp_list_categories('style=none&show_count=1&title_li=<h2>Categories</h2>'); ?>

Basically what we have done is passed on the argument that the style is none (default is list).

Removing Bullets from the Archive Section

If you've gotten this far, congratulations you have successfully removed the bullets in the categories section. If you have already guessed it by now yes the next step is pretty much the same but in this case they named it something else. To remove the bullets from the archive list find (also in sidebar.php):

<?php wp_get_archives('type=monthly'); ?>

and change it to:

<?php wp_get_archives('type=monthly&format=none'); ?>

Basically they changed the argument from style to format.

Removing Bullets from the Links Section

Now you're only left with removing the bullets in the links section also known as the bookmark section. This one was hard to pass the argument, maybe somebody could suggest a way, but here's what I did. Open up wp-includes/bookmark-template.php. Find function wp_list_bookmarks. We'll remove the <li></li> tags first since it comes up first. The first thing that comes up in the function is an array.

        $defaults = array(
        'orderby' => 'name', 'order' => 'ASC',
        'limit' => -1, 'category' => ", 'exclude_category' => ",
        'category_name' => ", 'hide_invisible' => 1,
        'show_updated' => 0, 'echo' => 1,
        'categorize' => 1, 'title_li' => __('Bookmarks'),
        'title_before' => '<h2>', 'title_after' => '</h2>',
        'category_orderby' => 'name', 'category_order' => 'ASC',
        'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">',
        'category_after' => '</li>'
);

The last two lines you'll see category_before => and category_after =>. Clear everything inside of the single quotes that they are pointing to. So you should be left with 'category_before' => " and 'category_after' => ". Go down a bit further and you'll find this piece of code:

if ( $categorize ) {
    //Split the bookmarks into ul's for each category
    $cats = get_terms('link_category', array('name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0));

    foreach ( (array) $cats as $cat ) {
        $params = array_merge($r, array('category'=>$cat->term_id));
        $bookmarks = get_bookmarks($params);
        if ( empty($bookmarks) )
            continue;
        $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before);
        $catname = apply_filters( "link_category", $cat->name );
        $output .= "$title_before$catname$title_after\n\t<ul class='xoxo blogroll'>\n";
        $output .= _walk_bookmarks($bookmarks, $r);
        $output .= "\n\t</ul>\n$category_after\n";
    }
} else {
    //output one single list using title_li for the title
    $bookmarks = get_bookmarks($r);

    if ( !empty($bookmarks) ) {
        if ( !empty( $title_li ) ){
            $output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before);
            $output .= "$title_before$title_li$title_after\n\t<ul class='xoxo blogroll'>\n";
            $output .= _walk_bookmarks($bookmarks, $r);
            $output .= "\n\t</ul>\n$category_after\n";
        } else {
            $output .= _walk_bookmarks($bookmarks, $r);
        }
    }
}

Do not be scared of its ginormous size. You can either go through and remove the two pairs of <ul></ul> or just comment them out. As I said they occur twice for different situations. Commenting it out will make it look like so:

if ( $categorize ) {
    //Split the bookmarks into ul's for each category
    $cats = get_terms('link_category', array('name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0));

    foreach ( (array) $cats as $cat ) {
        $params = array_merge($r, array('category'=>$cat->term_id));
        $bookmarks = get_bookmarks($params);
        if ( empty($bookmarks) )
            continue;
        $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before);
        $catname = apply_filters( "link_category", $cat->name );
        //$output .= "$title_before$catname$title_after\n\t<ul class='xoxo blogroll'>\n";
        $output .= _walk_bookmarks($bookmarks, $r);
        //$output .= "\n\t</ul>\n$category_after\n";
    }
} else {
    //output one single list using title_li for the title
    $bookmarks = get_bookmarks($r);

    if ( !empty($bookmarks) ) {
        if ( !empty( $title_li ) ){
            $output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before);
            //$output .= "$title_before$title_li$title_after\n\t<ul class='xoxo blogroll'>\n";
            $output .= _walk_bookmarks($bookmarks, $r);
            //$output .= "\n\t</ul>\n$category_after\n";
        } else {
            $output .= _walk_bookmarks($bookmarks, $r);
        }
    }
}

Scroll up a bit in the same file and you'll find the last piece of the puzzle. Just edit the code in function _walk_bookmarks().

function _walk_bookmarks($bookmarks, $args = " ) {
$defaults = array(
        'show_updated' => 0, 'show_description' => 0,
        'show_images' => 1, 'show_name' => 0,
        'before' => '<li>', 'after' => '</li>', 'between' => "\n",
        'show_rating' => 0, 'link_before' => ", 'link_after' => "
);

Change the <li></li> to " or for me I changed the 'after' => " to 'after' => '<BR />'. Just to have the space in there.

And there you have it you have successfully hard coded the bullets out. If you ever want them back just replace all of your files with the backed up ones. Once again I just want to remind you that I've only used this method because the modifying the styles didn't work for me. Do whatever is easiest and works.

Bonus: Removing Bullets from the Register Panel

As a bonus feature I'll throw in "how to remove bullets from the register panel" for free. Its very simple, in your sidebar.php file find:

<?php wp_register(); ?>

Just put into the brackets "," like so:

<?php wp_register(" ,"); ?>
TL
This entry was posted on Monday, September 21st, 2009 at 8:42 pm and is filed under Web Development, WordPress. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
BL

14 Responses to “Removing bullets from WordPress default theme menu”

  1. Marc Shaw Marc Shaw says:

    Hey, I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say GREAT blog!…..I"ll be checking in on a regularly now….Keep up the good work! :)

    - Marc Shaw

  2. Jerry Jerry Low says:

    @Marc Shaw: Thanks a lot Marc

  3. Hey, I found your blog while searching on Google. I have a blog on online stock trading, I'll bookmark your site.

  4. Polprav Polprav says:

    Hello from Russia!
    Can I quote a post in your blog with the link to you?

  5. Savannah Savannah says:

    Awesome blog!

    I thought about starting my own blog too but I'm just too lazy so, I guess I'll just have to keep checking yours out.
    LOL,

  6. Jerry Jerry Low says:

    @Polprav: Hey Polprav, thanks for your interest, but if you were planning on quoting on this exact article I'll have to apologize but this one isn't for sharing.

  7. Hey, I found your blog in a new directory of blogs. I dont know how your blog came up, must have been a typo, anyway cool blog, I bookmarked you. :)

  8. Hi,

    thanks for the great quality of your blog, each time i come here, i'm amazed.

    black hattitude.

  9. TilfelfTisk TilfelfTisk says:

    Other variant is possible also

  10. facebok facebok says:

    How you can find in the social network facebook. What are you represented?

  11. Jerry Jerry Low says:

    @black hattitude: Thank you black hattidude

    @TilfelfTisk: Yes there are other ways to remove the bullets, in fact there's the CSS alternative I've stated. Please share other great ones too.

  12. Indiana Jim Indiana Jim says:

    I am confused as to what text is supposed to be removed? everything in red? Everything in bold?

  13. Indiana Jim Indiana Jim says:

    I figured it out, but it was kind of screwy with my theme, considering I'm using Talian not the default.

  14. Jerry Jerry Low says:

    Hey Indiana Jim sorry it was a bit confusing as the code automatically bold some stuff. Glad it worked out for you.

Leave a Reply

Spam protection by WP Captcha-Free