• I am designing a theme that would operate a page to be viewed in a Facebook page iframe. Some of the menu items would need a target=”_top” property since some of the pages should not be viewed in the iframe.

    WordPress natively gives the option of setting a target in the same window or a new window. Is there a plugin that adds other target choices?

    If not, I’d be happy to experiment with writing such a plugin if someone would point me to a good tutorial or book. (The tutorials I have found so far don’t actually teach how to make a plugin that actually works.)

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter bgentry

    (@bgentry)

    I have since found out one way of solving this issue. It is to edit wp-admin\includes\nav-menu.php. Find this code:

    <select id="edit-menu-item-target-<?php echo $item_id; ?>" class="widefat edit-menu-item-target" name="menu-item-target[<?php echo $item_id; ?>]">
    <option value="" <?php selected( $item->target, ''); ?>><?php _e('Same window or tab'); ?></option>
    <option value="_blank" <?php selected( $item->target, '_blank'); ?>><?php _e('New window or tab'); ?></option>
    </select>

    This is the code that asks the user to select the link target options. To add an option for “_top” you can add this code before the </select>

    <option value="_top" <?php selected( $item->target, '_top'); ?>><?php _e('Top window-break iframe'); ?></option>

    When you create the WordPress menu that will appear on your Facebook iframe page, you can choose “Top window-break iframe.” This is the perfect solution when you want to provide an obvious link to the Facebook wall or other tabs on your Facebook page, because without the target=”_top” code Facebook will not let the link work.

    Of course, you would have to add this code every time you update WordPress. So I need to write a plugin for this. (That day will come…)

    Thread Starter bgentry

    (@bgentry)

    I have now found a better and easier way to solve this problem with my new plugin, Facebook iFrame Link Fixer.

    This plugin uses javascript to check whether a page is being viewed in an iframe. If so, it finds every link to a Facebook.com and adds a “target=_top” property to those links (unless they already have a target=”_blank” attribute designating them to open in a new window anyway).

    Hi bgentry!
    Just came across your post – I am looking for a similar thing – although in my case nothing to do with facebook.
    What I am after is the ability to assign a custom target to a particular menu item. For example target=”contentFrame”.
    I’m going to have a good look at your first attempt to see if I can adapt it to my purposes.
    Thanks!

    Thread Starter bgentry

    (@bgentry)

    daybo — I’m glad you’re looking into ways to do this. Are you looking for a way to have all menu items receive the same custom target, or give each menu item its own specific target?

    If you want the former, then a modified version of my solution could work. But if you want a custom, different target for each menu item, you’d need another solution. I have an idea, though, and you could contact me through my website to talk about ideas.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘adding custom target to menu links’ is closed to new replies.