Unlink Parent Pages for WordPress

I do not request donations for my plugins, but if you find this plugin helpful, please visit the WordPress.org plugin directory and give it a 5-star rating. Thanks!

Summary

Unlinks parent pages in page menus and lists. Useful for creating dropdown menus with top-level placeholders. Affects the output of wp_list_pages and wp_page_menu.

IMPORTANT: This plugin is not compatible with the Mystique theme, nor is it compatible with the WordPress 3.x custom menu system (that is, menus created using the drag-and-drop menu builder under Appearance->Menus). If you want to create an unlinked parent menu item with the Mystique theme, install Mark Jaquith’s Page Links To plugin, and put a ‘#’ (hash/pound) mark in the ‘Point to this URL:’ field to create a dummy link. For the WP3 menu builder, use a ‘Custom Link’ with a ‘#’ mark in the URL field. Refer to the documentation in the WP Codex if you need more help.

Description

When activated, this plugin unlinks parent pages (that is, pages that have child pages underneath them in a hierarchy) in page menus and lists. It affects the output of wp_list_pages and wp_page_menu, as well as all plugins and widgets that use those functions.

The plugin works by turning the parent page links into ‘dummy links’. That is, it replaces the href attribute on parent menu items with a ‘#’ (hash/pound) mark. A dummy link is just like a regular link, except that it leads back to the current page when clicked. The dummy links are given an inline style “cursor: default” to prevent the mouse pointer from turning into a hand when hovering over unlinked menu items.

Options

To configure the plugin options, go to the Settings menu in the WordPress admin panel and click on Unlink Parent Pages. (Here is a screenshot of the options page.)

Use Dummy Links

Turned on by default as of Unlink Parent Pages version 1.3. If you uncheck this box, the plugin will unlink the parent pages by replacing the anchor tags with span tags. In some themes, this may cause problems with CSS styling. In order to fix this, you would need to add an additional selector to any rule that targets the anchor tags (see the FAQ for more information). If you are not experienced in writing CSS selectors, then it is strongly recommended to stick with dummy links.

Unlink Current Page

Unlink the current page, in addition to the parent pages.

Remove Link Titles

Remove the title attribute from the links (stops the tooltip from popping up when the mouse hovers over the menu items). This does not have anything to do with unlinking parent pages, but it’s something a lot of people want, so I decided to include it.

Maximum Depth

The maximum depth setting controls how many levels in the hierarchy of pages are to be unlinked. It works exactly like the ‘depth’ option for wp_list_pages, as follows:

  • 0 (default) Unlinks all parent pages, anywhere in the page hierarchy.
  • 1 Unlinks top-level parent pages only.
  • 2, 3, … Unlinks parent pages to the given depth.
  • -1 Do not unlink any pages (specify individual pages instead).

Unlink Specific Pages

You can specify which pages you want unlinked, using a comma-separated list of page IDs (example: 3,7,31). It works exactly like the ‘exclude’ option for wp_list_pages. If you want only the specified pages to be unlinked, then set max depth to -1.

Installation

  • Upload ambrosite-unlink-parent-pages.php to the /wp-content/plugins/ directory.
  • Activate the plugin through the Plugins menu in WordPress.
  • Go to the Settings menu in the WordPress admin panel, and click on Unlink Parent Pages to configure the plugin options.
  • All parent pages in menus created with either wp_list_pages or wp_page_menu will become unlinked as soon as the plugin is activated. It will also automatically unlink newly created parent pages as the page hierarchy is built.

Frequently Asked Questions

I installed the plugin but it does not seem to be working. Why?

Unlink Parent Pages only affects the output of wp_list_pages and wp_page_menu. If your menu is not being generated by either of those functions, then the plugin will not work. If you want to test whether this is an issue with your menu, put the default ‘Pages’ widget into your sidebar. The Pages widget uses wp_list_pages, so if the pages are unlinked there, and not in your navigation menu, it means that your menu is not using wp_list_pages.

I know of two specific cases where this is a problem: the Mystique theme, and the WordPress 3.x custom menu system (that is, menus created using the drag-and-drop menu builder under Appearance->Menus). The WP 3.x custom menus are generated by the wp_nav_menu function, while the Mystique theme uses a non-standard custom function called mystique_list_pages. If Unlink Parent Pages detects either of these cases, it will display a warning message.

Is this plugin compatible with my favorite menu management plugin?

Unlink Parent Pages has been tested and is compatible with a number of other popular menu management plugins, including Page Menu Editor, Page Lists Plus, Page Links To, Sub Pages Widget, Exclude Pages, and All In One SEO Pack. It is probably compatible with most other plugins as well.

I do not want to use dummy links. How can I fix my menu styles when the parent pages are unlinked?

If you uncheck ‘Use Dummy Links’, the plugin will unlink the parent pages by replacing the anchor tags (<a>) with span tags (<span>). In some themes, this may cause styling problems if there are CSS selectors targeting the anchor tags that have been removed. In order to fix this, you must add an additional selector to any rule that targets the anchor tags. The CSS rules are different for every theme, so I cannot give specific instructions, but as a general example, if your menu styles look like this:

#menu li a {
some styles ...
}

Then you would need to add an additional selector which targets the span:

#menu li span,
#menu li a {
some styles ...
}

As an example, here are the rules that would need to be added to the bottom of ‘style.css’ in order to fix the Twenty Ten theme (in WordPress 3.1):

#access span {
color: #aaa;
display: block;
line-height: 38px;
padding: 0 10px;
text-decoration: none;
}
#access ul ul span {
background: #333;
line-height: 1em;
padding: 10px;
width: 160px;
height: auto;
}
#access li:hover > span,
#access ul ul :hover > span {
background: #333;
color: #fff;
}

Changelog

1.4

  • Fixed a bug that could potentially cause “undefined variable” and “headers already sent” warnings.

1.3

  • Added option to unlink the current page.
  • Added option to remove link titles.
  • Dummy links turned on by default.
  • Added inline style “cursor: default” to dummy links, to prevent the mouse pointer from turning into a hand when hovering over unlinked menu items.
  • Added warning messages for Mystique theme and WP 3.x custom menus.

1.2

  • Refactored to improve performance.

1.1

  • Added option to unlink specific pages.

1.0

  • Initial version.

More Plugins

Comments

  1. moox says:

    How would I go about having this work with categories rather than pages?

  2. ambrosite says:

    @moox The plugin would have to be completely rewritten. You would need to take wp_list_categories from wp-includes/category-template.php, and the Walker_Category class from wp-includes/classes.php, and modify them in the same way that I modified wp_list_pages and the Walker_Page class for my plugin. It is not a trivial project.

    I did not think there were very many people using categories as menus, but if there is demand for it, I’ll consider writing an “Unlink Parent Categories” plugin as a separate project.

  3. CV13 says:

    Love your plugin. I just updated to Twenty Ten 1.1 and the plugin no longer works (set to default 0 with dummy links). I tried both de-acvtivating/re-activating and re-installing. Any thoughts or plans to update plugin? Thanks!

  4. ambrosite says:

    @CV13 I was testing the plugin with WP 3.0 a few days ago and ran into a similar problem. I’m looking into it now, but in the meantime you can work around it by setting “max depth” to -1 and using the Unlink Specific Pages field to list the pages that should be unlinked.

  5. CV13 says:

    Worked like a charm…thanks!

  6. Day1 says:

    If I would like to replace the \a\ with \span class=\opmaak\\, could it be done with this plugin?
    And What about the compatibility with wordpress 3?

    sorry for repost, but something went wrong.

  7. ambrosite says:

    @Day1 Yes, you can easily make that change. Edit ambrosite-unlink-parent-pages.php, and find the following code (around line 134):

    $link_open = '<span';

    Replace it with:

    $link_open = '<span class="opmaak"';

    Then check the Use Dummy Links box on the plugin options screen.

  8. Day1 says:

    Hey! Thanks! that worked for me :).

  9. felix says:

    hi..pls help me

    i got warning error “Warning: Missing argument 2 for wp_list_pages_unlink_parents()”

    even i used dummy link..

  10. ambrosite says:

    @felix I have not seen that error before. Are you running WordPress in debug mode? That is, do you have the following in your wp-config.php:

    define(‘WP_DEBUG’, true);

  11. (It appears the first comment timed out)

    Ambrosite, thank you for your plugin. I’m toying around with the new Mystique them that was published on the WordPress theme database (http://wordpress.org/extend/themes/mystique). I think they may handle their menu a little differently, because the plugin does not seem to detect the menu on any options (even if it is set to -1 and I use specific pages). Does it work for you or might I be missing something?

  12. ambrosite says:

    @Judson No timeout, it’s just that comments with links require moderator approval. I do not have any experience with the Mystique theme, however I can tell you that the plugin is not compatible with the new drag-and-drop custom menu system that was introduced in WordPress 3.0. That is because the custom menus do not use wp_list_pages. So if you have used that feature to create a custom menu, my plugin will be ineffective.

  13. ambrosite says:

    If you want to test whether there is an issue with custom menus, put the “Pages” widget into your sidebar. The default Pages widget uses wp_list_pages, so if the pages are unlinked there, and not in your navigation menu, it means the nav menu is not using wp_list_pages.

  14. Austin says:

    > And What about the compatibility with wordpress 3?

    With the new menus in WP 3 there is no real need for the plugin as a custom link can be made anyway – just set it up with no URL and then place any pages/cats you want underneath it.

    Awesome plugin for themes using wp_list_pages tho’ :]

  15. ambrosite says:

    @Austin You are right of course, if you are using the WP 3 menu system, the plugin is not needed, that’s why I haven’t spent any time updating it. But it is still useful for pre-WP3 themes that use wp_list_pages to create their menus.

  16. I disagree, the WP Menu system isn’t as flexible as the wp_list_pages() function for tasks such as automatically generated menu lists. Sadly one thing missing from the WP core is unlinking parents and now that this plugin isn’t working as intended in WP3 the problem of doing so remains unsolved. Please don’t give up on this very useful addition to the WP toolbox.

  17. ambrosite says:

    @Pete Thanks for your feedback. Unlink Parent Pages is a lower priority than my other plugins, but I will continue to support it. And may I ask, how is it not working for you? Because some people say it works on 3.0.x, and some say it doesn’t.

  18. Trey says:

    Hey Ambrosite, I have the same question as Judson Hudson above, with the same WP Template, and I put pages in the widget area, and the links still have parents. Do you know if creating a custom wp3 menu will remove the parents with your plugin? Thanks!

  19. ambrosite says:

    @Trey I don’t know the details of your particular template, but I have seen WordPress themes that go so far as to create their own custom version of wp_list_pages. If your theme/template is using anything other than the standard core wp_list_pages to generate the menus, then my plugin will be ineffective. Using the WP3 custom menus will not help either, since my plugin does not work with custom menus.

  20. ambrosite says:

    For those who are looking for a way to unlink parent menu items in a WP3 custom menu, I just found an article that offers a possible solution:

    http://www.realm9.com/2010/12/solved-making-parent-menu-items-in-wordpress-menus-non-clickable/

  21. ambrosite says:

    I have just confirmed that Unlink Parent Pages is NOT compatible with the Mystique theme. That is because Mystique does not use wp_list_pages to generate the navigation menus. Rather, they have defined their own custom function called ‘mystique_list_pages’ at line 270 of the following file:

    wp-content/themes/mystique/lib/core.php

    I have no idea why they felt the need to create a non-standard page list function, rather than just apply a filter to wp_list_pages. But with so many themes doing weird crap like this now, added to the fact that the WP3 custom menu system does not use wp_list_pages either, there are an ever-increasing number of scenarios where the Unlink Parent Pages plugin will not work at all. Because of this, I am seriously considering retiring the plugin, but if anyone feels strongly that it should still be maintained, please let me know.

  22. Zephbane says:

    First, thank you for this plugin.

    Unfortunately, it doesn’t work completely with the Piano-Black theme. If I don’t use \Use Dummy Links\, then the unlinked page in the menu has the formating messed up and the menu doesnt work. Any suggestions to where I might look to find the problem? Using Dummy Links is ok, but gives the impression that the menu (page) can be clicked and will go to another page.

    In an ideal world, my preference would to have an option for: If unlinked, mouse cursor doesnt change to link hand, but still changes text color as if it was a link.

    Again, these are just wishes :) Thanks for the plugin!

  23. ambrosite says:

    @Zephbane If all you want to do is stop the cursor from changing into a hand when it’s pointing to an unlinked page, that should be easy enough. Edit ambrosite-unlink-parent-pages.php, and find the following code (around line 132):

    $link_open = '<a href="#"';

    Replace it with:

    $link_open = '<a href="#" class="no-hand"';

    Then add the following to the end of your style.css file:

    .menu a.no-hand { cursor: default; }

  24. ambrosite says:

    That last question has me thinking: the default cursor could also be specified as an inline style at that same spot in the code. I might release an updated version of the plugin just to make that change.

  25. Zephbane says:

    Thank you for the suggestion. Unfortunately it didn’t work. The results were mixed. It seems to unformat linked menu items, while keeping the format of unlinked one. For the linked menu items, the cursor didnt change. For unlinked ones it did change. Hehe, seems like it had the opposite effect :)

    I’m convinced that the theme I am using is interfering with this… or should I say, has it’s own functions to handle how page unlinking works.

    If you do release an update, I’ll be sure to grab it and let you know how it works for my situation :)

    Thanks again!

  26. ambrosite says:

    @Zephbane I did notice that your theme is using JavaScript to control the menus. If you temporarily disable JavaScript in your browser, you will see that your menus stop working altogether. That is probably what is causing the interference. Unfortunately, there is nothing my plugin can do about that.

  27. Anonymous says:

    Interesting… Well that stinks :) I guess for now using your plugin with dummy links will suffice. Until I can learn more about this php/javascript stuff. Thanks for your support, ambrosite.

  28. Elena says:

    Hi, please can somebody tell me if Mouse will change over the link. I mean the hand symbol, I would like to unlink parent menue and I would like that the mouse didn’t change and people think that there is a link. Thank you very much for a respond. Please help me this issue makes me crazy. Lovely Elena

  29. ambrosite says:

    @Elena If you check “Use Dummy Links” then yes, the mouse will change to a hand symbol even if the page is unlinked. I plan to release a new version of the plugin later this month to address that issue. In the meantime, you can try the solution I suggested to Zephbane.

  30. ambrosite says:

    Version 1.3, which includes the mouse pointer fix, has just been released. Unlink Parent Pages lives on, at least for a while longer.

  31. Zephbane says:

    Hey ambrosite… I just downloaded the latest version for this plug in and guess what… It works prefectly! No linkhand over unlinked pages anymore – exactly what I was looking for.

    Thanks so much for pushing this update. It’s very appreciated.

  32. marion says:

    Hi, I hope you can release a version that can unlink parent categories / custom taxonomies…thanks

  33. ambrosite says:

    @Zephbane Thanks for the follow-up and feedback! I’m glad to hear the update worked for you.

  34. ambrosite says:

    @marion You are the second person who has requested an Unlink Parent Categories plugin, so I just might have to do it! I’ll take a look at that over the next couple of weeks.

  35. Mike says:

    Hello

    Unlink Parent Categories would be a life saver for me!

  36. ambrosite says:

    @Mike Well that makes three requests for Unlink Parent Categories! I will definitely do it — I’m planning to update some of my plugins after WordPress 3.2 is released, so I’ll work on this at the same time.

  37. Mike says:

    That’ll be excellent. Thank you so much!

  38. ambrosite says:

    For those who have requested the Unlink Parent Categories plugin, it is now available for download:

    http://www.ambrosite.com/plugins/unlink-parent-categories-for-wordpress

  39. Tony says:

    Thanks for your Plugin !!
    That’s so great !!!

    Excellent.

    Peace.

  40. mariah says:

    I have not loaded your plugin yet because I read your message about custom menus. I’m running on the most current WP and have created a custom menu. Where exactly would I add this # to make the link dead? Thanks in advance for your help!!! I’ve been trying to figure this out for a while now, I would think this was easier.

  41. ambrosite says:

    @mariah As I explain in the plugin summary, if you want to create an unlinked parent menu item with the WP menu builder, use a ‘Custom Link’ with a ‘#’ (hash/pound) mark in the URL field. Refer to the documentation in the WP codex if you need more help:

    http://codex.wordpress.org/Appearance_Menus_Screen#Custom_Links

  42. Darren says:

    Thank you so much for this, have been looking everywhere for a plugin like this! Works like a charm for me in WordPress3.3.2 with my theme which is the pureVISION theme. Works with dummy link enabled otherwise the menu item disappears. Have left feedback on wordpress. Many thanks again :)

  43. Jhoanne says:

    I use the latest WP version for our fan site, and it supports Custom Menus. I thought it wouldn’t work just like you said, but it did!

Comments are closed. If you have a question about this plugin, please create a thread on the WordPress support forum and I will answer it there.