Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#14652 closed enhancement (wontfix)

add '_parent' or '_top' to the wordpress menus 'link target' advanced options

Reported by: erikshosting Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Menus Keywords:
Focuses: Cc:


The advanced menu builder option 'link target' only contains attributes _self, and _blank. This needs to be expanded to _parent, or _top.

Change History (12)

#1 @scribu
5 years ago

  • Component changed from General to Menus

#2 @Denis-de-Bernardy
5 years ago

-1. We ought to give two options: one opens a new window, the other breaks out of any frame and loads in it's own frame. And they should be labeled "current window" and "new window". Frames are too 1995, and shouldn't be used at all. And most users have no clue what those vales are anyway.

#3 @scribu
5 years ago

I agree. An 'Open in a new window' checkbox should be enough, UI wise.

#4 @erikshosting
5 years ago

'new window' and 'current window' are already options, but 'current window' is targeted to '_self', rather than '_top' or '_parent'. so there is currently no option to break out of frames.

I know that frames are "too 1995", which is even more reason to add the '_top' or '_parent' attribute so we can break them when needed.

Most casual users don't know what these options are, which is why they are already hidden as an advanced screen option. Shouldn't this advanced option be complete?

If you point me to the appropriate file, I'll start looking into adding _parent, or changing the 'current window' option from '_self', to '_parent'.

#5 @erikshosting
5 years ago

I just added a custom walker to output these attributes, but I still think that the _top $arg should be added to target options...

#6 @nacin
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

I agree. An 'Open in a new window' checkbox should be enough, UI wise.

Agree completely.

#7 @davelewis@…
4 years ago

I have a site where I have no choice but to use a frameset on one particular page (long ugly story involving a legacy system hosted at another domain so I can't use an iFrame since there is no way to size the iFrame to the content without access to both domains). So I need a big 'ol ugly frameset circa 1995. No choice other than maybe an external link or new window. So I need all other links in the menu to have the ability to break out of the frameset.

#8 @scribu
4 years ago

@davelewis: That's an edge case that should be handled via a plugin.

#9 @nacin
4 years ago

Followup: #17521: Menu Link Target should be a checkbox

You should be able to filter the link target for all menu items, thus preventing the need to even store target=_top in the database.

#10 @davelewis@…
4 years ago

Fair enough. I'm working on it now. I was considering making my own walker... but the filter idea sounds better. Thanks. Oh how it pains me to even have to use a frameset. But anyway...

Last edited 4 years ago by davelewis@… (previous) (diff)

#11 @nacin
4 years ago

function nacin_filter_menu_target_sorry_world( $menu_item ) {
    if ( ! is_admin() && empty( $menu_item->target ) )
        $menu_item->target = '_top';
    return $menu_item;
add_filter( 'wp_setup_nav_menu_item', 'nacin_filter_menu_target_sorry_world' );

That should probably work.

#12 @davelewis@…
4 years ago

Beautiful. Thanks!!! I was attempting to use the pre_link_target or pre_link_url filter along with some PHP string replacement. wasn't having much luck :)

Last edited 4 years ago by davelewis@… (previous) (diff)
Note: See TracTickets for help on using tickets.