0

I am looking for, like the title of this question indicates, a custom menu in wordpress where the menu title itself is a link. It seems like a very simple thing, but after a lot of searching I've come up with nothing.

More explanation:

Here is what I have:

My Custom Menu
  Link 1 (goes to page 1)
  Link 2 (goes to page 2)
  Link 3 (goes to page 3)

Here is what I want:

My Custom Menu (goes to w/e page I choose to link it to)
  Link 1 (goes to page 1)
  Link 2 (goes to page 2)
  Link 3 (goes to page 3)

Simple, right? So, is there a plugin for this, or do I need to write on?

2
  • Any progress? Was my answer helpful? Do you still miss something?
    – fuxia
    Oct 6, 2012 at 22:28
  • @toscho That is an excellent question. I'm afraid it's been so long, now, that I do not recall. If someone wishes to verify your answer as working, I'll accept it. May 23, 2016 at 20:16

1 Answer 1

1

You can filter the title of most widgets and change the markup. The name of the filter is 'widget_title' and the third parameter tells you the type of the filtered widget.

Sample code, not tested:

add_filter( 'widget_title', 'wpse_52108_nav_widget_title_link', 30, 3 );

/**
 * Changes the title for the nav menu widget.
 *
 * @param string $title
 * @param string $instance
 * @param string $id_base
 * @return string
 */
function wpse_52108_nav_widget_title_link( $title, $instance = NULL, $id_base = '' )
{
    return 'nav_menu' === $id_base ? "<a href='http://example.com'>$title</a>" : $title;
}

The $id_base is the first parameter in parent::__construct() in the widget class. For the nav menu widget it is:

parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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