One common question in the WordPress IRC Channel is how to add external links, or links to content other than pages, to the output of wp_list_pages, usually not that exactly but that is what they mean. You can of course modify your theme by inserting <li><a href="http://example.org">Example.org</a></li> immediately following the wp_list_pages function however, this is not always the best solution. In my case I am working on developing a theme for distribution and testing it in the best way possible by running it as my main theme on my site. Since I want extra links to appear there and I don’t want to have content in the theme that will not be distributed to users, filtering the output of wp_list_pages works wonderfully.
You can put this following code in your themes functions.php, or in a plugin. Since I am trying to keep from modifying my theme, a plugin is the better option.
add_filter('wp_list_pages', 'add_forum_link');
function add_forum_link($output) {
$output .= '<li><a href="http://forum.example.org/">Forum</a></li>';
return $output;
}
The above code will add a link to a forum at http://forum.example.org/.
Enjoy!
Pingback: Statische Links zu WordPress Seiten hinzufügen - bueltge.de [by:ltge.de]
Pingback: Add Links To WordPress List Pages - This, WordPress, Page, ‘Example, Example, Subpage - WP Engineer
Nice code snippet…but do you have an idea how i can add a “news” link between two other pages?
I thought about a solution with str_replace… but maybe there is an easier way?
greets chukki
It’s me again :)
I solved it in a way like this:
add_filter(‘wp_list_pages’, ‘add_home_link’);
function add_home_link($output) {
$output = str_replace(”,’News\n’, $output);
return $output;
}
It works very good. I searched for the position where i want to add the link and put it before it.
Pingback: Add Links To WordPress List Pages | Omelyn.com
Pingback: 16 best practise Tipps: statische Seiten in WordPress
Pingback: 20 Tipps zu den statischen Seiten in WordPress
Exactly what I was looking for. I needed to add a link to a post category on my header and this worked great! Thanks!