0

I have the following code the generates the sitemap.

 wp_list_pages(
                                array(
                                    'exclude' => '5',
                                    'sort_column' => 'ID',
                                    'title_li' => ''
                                )
                            );

It generates a hierarchy of my Pages but it also has links to my parent pages.

enter image description here

check the screenshot above. I only need the title for all the parents not the link.

Please help. Thanks.

  • why not creating your own function as this one is a default WP one and it behave like this – Temani Afif Dec 8 '17 at 8:10
  • Can you please provide any example code for this? I am new to Wordpress. – Ahsan Ali Dec 8 '17 at 9:15
  • You have at least five choices: 1) extend Walker_Page to use within wp_list_pages() ; 2) create a navigation menu; 3) write your own function; 4) filter out <a> tag from the return of wp_list_pages() using regular expression; 5) use CSS. – Max Yudin Dec 8 '17 at 9:20
1

You can use get_pages() instead and write some custom code like this :

$args = array('exclude' => '5',
             'sort_column' => 'ID'
       )
$pages = get_pages($args); 
  foreach ( $pages as $page ) {
    echo $page->post_title;
  }

You may of course elaborate more the code in order to obtain a tree.

You may also check the source code of wp_list_pages() and you will see that there is the get_pages() function, so you may also copy its code and modify it :

https://developer.wordpress.org/reference/functions/wp_list_pages/#source

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.