Non page link in wp_list_pages

I would like a navigation something like this.

Home - People - About - Services - Contact

Home, About, Services and Contact are all pages.

People DOES NOT have a page, I would like to use this link to open a second Navigation.

Is it possible to add a link in wp_list_pages that doesn't link to a page.

Is it also possible to add a id to this link that doesn't have a page.

I would like the code to look something like this.

    ul
      lia href="Wordpress link"Home/a/li
      li id="people"a href="No Page"People/a/li
      lia href="Wordpress link"About/a/li
      lia href="Wordpress link"Services/a/li
      lia href="Wordpress link"Contact/a/li
    /ul  

Topic wp-list-pages Wordpress

Category Web


I don't know what you mean by "open a second navigation". That could mean several things. But to get an "empty" link you have a couple of choices:

Option #1-- aka, easy but kind-of a hack

Add a menu item with the "Custom Links" form. You have to provide an URL but you can delete the URL after the item is added to the menu. You will end up with <a>People</a> in the menu. You can't add an id but you can add a class from the menu item's dialog.

Option #2-- Filter wp_list_pages

function prepend_to_page_walker_wpse_103936($output) {
  $pattern = '|<ul>|';
  $output = preg_replace($pattern,'<ul><li id="people"><a href="No Page">People</a></li>',$output,1);
  return $output;
}
add_filter('wp_list_pages', 'prepend_to_page_walker_wpse_103936');

Option #3-- Write a walker


Option #1 is obviously easier if you can use it, but it sounds like you aren't. Thought I would through it in though.

Option #2 should work. preg_replace with the fourth limit parameter should only replace the first occurrence of <ul>.

Option #3 would give you the most flexibility but it looks like you'd need to replace a significant method to do it (or this one), and I don't see the point of that effort. It is possible that I am missing something though.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.