Unlink Parent Categories 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 categories/taxonomies in category menus and lists. Useful for creating dropdown menus with top-level placeholders. Affects the output of wp_list_categories.

Description

When activated, this plugin unlinks parent categories (that is, categories that have child categories underneath them in a hierarchy) in category menus and lists. It affects the output of wp_list_categories, as well as all plugins and widgets that use that function.

The plugin works by turning the parent category 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.

The plugin is compatible with custom hierarchical taxonomies. To create a list of custom taxonomy terms, you must set the ‘taxonomy’ parameter of wp_list_categories. See the FAQ for more information.

Options

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

Use Dummy Links

If you uncheck this box, the plugin will unlink the parent categories 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 Category

Unlink the current category, in addition to the parent categories.

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 doesn’t have anything to do with unlinking parent categories, but it’s something a lot of people want, so I decided to include it.

Unlink Specific Categories

You can specify which categories you want unlinked, using a comma-separated list of category IDs (example: 3,7,31). If you want only the specified categories to be unlinked, then check the “Unlink specific categories only” box.

Installation

  • Upload ambrosite-unlink-parent-categories.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 Categories to configure the plugin options.
  • All parent categories in menus created with wp_list_categories will become unlinked as soon as the plugin is activated. It will also automatically unlink newly created parent categories as the category hierarchy is built.

Frequently Asked Questions

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

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

How can I use this plugin with custom taxonomies?

You must set the ‘taxonomy’ parameter of wp_list_categories in order to generate a list of custom taxonomy terms, as explained in the WordPress Codex.

Once the taxonomy parameter is set, the plugin will unlink the parent terms in the list, just as it does with normal categories. You can also set a custom taxonomy for the default Categories widget, by putting the following code into functions.php:

function wc_args( $cat_args ) {
$cat_args['taxonomy'] = 'my_taxonomy';
return $cat_args;
}
add_filter('widget_categories_args', 'wc_args');

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 categories 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 ...
}

Changelog

1.0

  • Initial version.

More Plugins

Comments

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.