[Resolved] Hook before menu title (nav)

Home Forums Support [Resolved] Hook before menu title (nav)

Home Forums Support Hook before menu title (nav)

  • This topic has 7 replies, 3 voices, and was last updated 4 years ago by David.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #895756
    Sebastien

    Hi,

    I would like to hook “Author” field before the menu’s title (displayed into the nav bar) of the post type: PAGE.

    Can you help me please?
    thanks

    #895791
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    I’m not too sure what you mean. Can you share any examples?

    #896000
    Sebastien

    Thanks Tom for answering.
    Unfortunatly, I don’t have any example..of what I want, but I have the example of my Menu/Submenu in the first post.

    In my Main Menu (postionned into my nav bar) there is a SUBMenu.
    This submenu is composed by 6 link. I guess these 6 links are Post Type PAGES, that’s why they also should be linked to every field composing a PAGES right?.

    My need is so : for each link (page), I would like to get the data of the “post_author” and place it before the Title. That’s what I’ve called “hook before menu title” above.
    thanks

    #896362
    Tom
    Lead Developer
    Lead Developer

    Ah, so the page author would show before the sub-menu item title? This would definitely cramp the sub-menu quite a bit?

    You could potentially filter the menu output, but it’s pretty complex. It looks like you tried to add a shortcode in there – does the shortcode have the code to show the author? If so, you could use a plugin like this to enable shortcodes in your menu items: https://wordpress.org/plugins/shortcode-in-menus/

    #896888
    Sebastien

    Hi Tom,

    Yeah I made many tests in my menus..

    Post_author is not my real need, but if it works with author it will work with many others fields.
    I explain to you my point:
    I’ve create a custom relationed field into my post type PAGES.
    In this field, I’ve stock my SVG inline.

    The point is, I want be able to use SVG inline easly (with only one place where they are stocked).
    I easly could use some shortcode to call directly the Posts Type SVG… but I would prefer use not any 3rd party shortcode / plugin.

    What I want is: Get the inline svg stored in my field “SVG” for each pages and use it before the title of each sub menu.

    To be honest I would prefer 100 times don’t use any plugin, and work with filters…as you mentionned above.. anyway if it is too much complex, it is too much complex… !

    #897056
    Tom
    Lead Developer
    Lead Developer

    There’s nothing really wrong with (most) plugins. Most of the time they’re just code that someone else has taken the time to write so you don’t have to.

    Is your shortcode built to grab the SVG from your custom field? If so, have you tried the plugin I mentioned to enable shortcodes in menu items?

    #897607
    Sebastien

    Hey Tom,

    The solution of using Shortcode + the plugin to display shortcode in menus item works partially because the shortcode I use, doesn’t work outside of active page :

    function db_custom_field_shortcode() {
    	$custom_field = get_post_meta( get_the_ID(), 'svg', true );
    	$cf_content = '<p class="custom-class">' . $custom_field . '</p>';
    	return $cf_content;
    }

    the problem is, that it get the ID of the active page … but I menus items are displayed into every pages (I met the same issue when using this kind of shortcode in WPSHOWPOST)

    I can live with that since I can use another plugin to create the shortcode that works:
    In fact, this new shortcode doesn’t point anymore to the field of the active page, but directly to the Post Type SVG (where inline code are stored): as I said before, the “svg” field of my PAGES, is a relationned field that provide svg code from Post Type SVG.

    … but I’m not really happy with this solution because I don’t use anymore the field of the page.. (I lost in “automatization”).

    That why I’m still looking for a solution that would get the data stored in the field of the Post Type PAGE, and displays it when every menu item is displayed (even if I’m not using the active page) using the relation between item menu – pages.

    OR … a new shortcode that point directly to the PostType SVG, grabbing the field “Customfield”, and the slug: “My custom SVG”: a shortcode like this [field: “SVG” , “CustomField”, “My custom SVG”]

    #897754
    David
    Staff
    Customer Support

    Considering your other post – i assume you found a working solution?

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.