• Resolved semyl

    (@semyl)


    I like this plugin and would really like to adapt it to append an anchor to the end of every menu item (based on a shortcode attribute). Can you point me in the direction of how to do this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author linux4me2

    (@linux4me2)

    Hi @semyl,

    I’m not sure I understand what you mean, but I think you’re saying you want an anchor at the end of some menu links; e.g:

    
    https://yourdomain.com/your-page/#theanchor
    

    In that case, all you need to do is go into Appearance -> Menus, select the menu you are using in your Menu In Post shortcode, and add a menu item of type “Custom Link,” adding the anchor to the end of the link. Save the menu, and you should be good to go.

    Thread Starter semyl

    (@semyl)

    Hi @linux4me2,

    Yes I want to add #theanchor to the end of ALL links in that menu. I don’t want to use Custom Link as that means my menu won’t update if slugs change. Also, I want this added to the end of all the items of this particular menu. I was hoping there was a way to do it programmatically.

    A quick google mentioned something called a walker that could do this. Seeing as this particular menu is one I use with Menu in Post, I was hoping there could be a simple way to extend the plugin so the shortcode could have an option to to append something at the end of every menu link (I could see other use cases for this, e.g. adding language variables to the URL).

    Plugin Author linux4me2

    (@linux4me2)

    Hi @semyl, sure, I think it would be pretty easy to add an option in the shortcode to append something to the end of every menu item, but I’m having a hard time wrapping my head around why you’d want the same anchor on ever link.

    Let me see what I can do, and I’ll post back here when I have it ready.

    Plugin Author linux4me2

    (@linux4me2)

    Hi @semyl

    I just uploaded a new version, 1.1.6, which adds the ability to append a text string to the end of every menu item in a menu. You’ll find the new UI in Tools -> Menu In Post includes it, and it’s described in the Help section.

    If you prefer to add it to an existing shortcode, you’d just add:

    
    append_to_url="#myanchor"
    

    to the shortcode.

    I’ve tested it with both the dropdown style and the regular list style, and it seems to work fine for both anchors and variables.

    Thread Starter semyl

    (@semyl)

    That’s fabulous, thank you @linux4me2! I’ll test it out and get back to you if I have any issues.

    To explain in case you are curious – that particular menu is for categories (and subcategories) of a video database. The videos are a custom post type. Users will likely click through a lot of categories/video pages in quick succession, so we want links in this menu to jump below the hero/back to this menu. However, if they are coming in from elsewhere (e.g. the main website menu at the very top of the page, or a direct URL), then it makes sense for them to see the site header and hero first (i.e. no anchor).

    • This reply was modified 3 years, 11 months ago by semyl.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Prepending anchors to links’ is closed to new replies.