Adding Additional Links to the Output from wp_list_pages Part 2

Earlier this month I wrote about “Adding Additional Links to the Output from wp_list_pages”. I have recently realized that the process of adding new or additional links could be easier. Rather than manually editing the plugin or function every time you want to add a new link or remove a link we can leverage existing WordPress functionality to handle this.

The existing WordPress functionality that we will leverage are Links/Bookmarks.

We will start with the code. Add the following code to your themes functions.php or as a plugin.

add_filter('wp_list_pages', 'add_bookmarks_to_menu');
function add_bookmarks_to_menu($output) {
        $bookmarks = (array) get_bookmarks('hide_invisible=0&category_name=wp_list_pages');
        foreach ( $bookmarks as $bookmark ) {
                $output .= "<li><a href='{$bookmark->link_url}' title='{$bookmark->link_name}'>{$bookmark->link_name}</a></li>\n";
        }
        return $output;
}

Now we head to the WordPress admin and browse to Links->Add New. Type the name as you want it to show up in your menu, the web address of your link, add this link to a new category called ‘wp_list_pages’, select ‘Keep this link private’ and click ‘Add Link’.

Placing the link in a category called ‘wp_list_pages’ will allow us to grab only links from that category and selecting ‘Keep this link private’ will keep it from showing up in the Links/Blogroll/Bookmark section of your site.

Enjoy!

About Matt

IF YOU REALLY want to hear about it, the first thing you'll probably want to know is where I was born, and what my lousy childhood was like, and how my parents were occupied and all before they had me, and all that David Copperfield kind of crap, but I don't feel like going into it, if you want to know the truth.

In any case I am employed as a Senior Linux Systems Engineer at Rackspace in San Antonio, TX.

I spent the majority of my college years as an Astrophysics major specializing in black holes. When I got to my senior year and was studying 40 hours a week to stay on track I decided to bail and pursue an easier career.

I spend the majority of my time now contributing to WordPress, developing WordPress plugins, helping out in the WordPress IRC Channel, playing football (not American!), practicing Krav Maga, and last but not least, spending time with my Wife and Son.

This entry was posted in Code, PHP, Snippet, WordPress. Bookmark the permalink.

3 Responses to Adding Additional Links to the Output from wp_list_pages Part 2

  1. Pingback: 16 best practise Tipps: statische Seiten in WordPress

  2. buzzer says:

    Thanks. works perfectly.

  3. Pingback: 20 Tipps zu den statischen Seiten in WordPress

Leave a Reply

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

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre>