Remove wordpress parent links


/ Published in: PHP
Save to your folder(s)

If you have your wordpress subpages organized by parent pages... and you dont want the parent pages "clickable" this will fix you right up...


Copy this code and paste it in your HTML
  1. // Place this section in your functions.php
  2.  
  3. <?php
  4. function removeParentLinks() {
  5. $pages = wp_list_pages('echo=0&title_li=');
  6. $pages = explode("</li>", $pages);
  7. $count = 0;
  8. foreach($pages as $page) {
  9. if(strstr($page,"<ul>")) {
  10. $page = explode('<ul>', $page);
  11. $page[0] = str_replace('</a>','',$page[0]);
  12. $page[0] = preg_replace('/\<a(.*)\>/','',$page[0]);
  13. if(count($page) == 3) {
  14. $page[1] = str_replace('</a>','',$page[1]);
  15. $page[1] = preg_replace('/\<a(.*)\>/','',$page[1]);
  16. }
  17. $page = implode('<ul>', $page);
  18. }
  19. $pages[$count] = $page;
  20. $count++;
  21. }
  22. $pages = implode('</li>',$pages);
  23. echo $pages;
  24. }
  25. ?>
  26.  
  27. // Now just replace your wp_list_pages(); function with removeParentLinks(); //and away you go.

URL: http://bavotasan.com/tutorials/how-to-remove-the-links-to-parent-pages-in-the-wordpress-page-list/

Report this snippet


Comments


You need to login to view comments.