WordPress wp_list_pages includes Home link for no reason

Well, it’s never for ‘no reason’ but it can be hard to find.

I have been working with the free download ColorWay theme By InkThemes.com and while I like the theme it was annoying me that when I used the wp_list_pages function to get a list of child pages (which I logged earlier this year), it kept adding the Home page to the list as if it were a child of the page.

As it turns out after much tracking of the source of the issue, I find that the Colorway theme includes an add_filter function to insert the Home link at the top of the wp_list_pages function to build the main menu. I tracked this down to this file:

wp-contentthemescolorwayfunctionsinkthemes-functions.php

What I found was that the add_filter was being applied for the specific purpose and was then left as a persistent process.

at around line 46

wp_list_pages('title_li=&show_home=1&sort_column=menu_order');

and at around Line 63

add_filter('wp_list_pages, 'inkthemes_new_nav_menu_items');

Line 46 was inside a function which builds the main menu:

function inkthemes_nav_fallback() {
	?>
    <div id="menu">
        <ul class="ddsmoothmenu">
            <?php
               wp_list_pages('title_li=&show_home=1&sort_column=menu_order');
            ?>
        </ul>
    </div>
    <?php
}

Which I modified to basically place the add_filter as a part of this function only and added a remove_filter at the end to put it back to normal.

function inkthemes_nav_fallback() {
        // 20121103 thowden copied from line 63 to place relevant to this function only
        add_filter('wp_list_pages', 'inkthemes_new_nav_menu_items');
	?>
    <div id="menu">
        <ul class="ddsmoothmenu">
            <?php
			wp_list_pages('title_li=&show_home=1&sort_column=menu_order');
            ?>
        </ul>
    </div>
    <?php
     // 20121103 thowden added to reset the standard wp_list_pages function
     remove_filter('wp_list_pages', 'inkthemes_new_nav_menu_items');
}

So now the InkThemes menu will still work but will not perpetuate the wp_list_pages function change.

But, the body of the page list is still a problem and that is because line 63 as shown above is NOT in a function and is always applied. So the simple solution is to delete it, or comment it out of the code.

// 20121103 thowden to remove Home from list pages
//add_filter('wp_list_pages', 'inkthemes_new_nav_menu_items');

and all is well with the world again…

2 replies on “WordPress wp_list_pages includes Home link for no reason”

  1. Juliana says:

    Thank you, thank you, thank you, thank you! 🙂

  2. Ferry says:

    Thanx man! What an irritating ‘feature’ 🙂

Leave a Reply to Ferry Cancel reply

Your email address will not be published. Required fields are marked *