Site logo

[Resolved] using hooks on a template page

Home Forums Support [Resolved] using hooks on a template page

Home Forums Support using hooks on a template page

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1737193
    Davide

    Hi, is there a way to use an hook (in this case generate_menu_bar_items) only on a custom template? 

    Under the “display rules” in the Element menu there isn’t this possibility, so I guess it should be added via code (using something like https://developer.wordpress.org/reference/functions/is_page_template/ ? I’m not sure).

    Any hint?
    thank you!
    David

    #1737485
    Leo
    Staff
    Customer Support

    Hi David,

    Not 100% sure what you are after but would this filter be helpful?
    https://docs.generatepress.com/article/generate_hook_element_display/

    It can be used when the display rules don’t cover the condition you are after.

    Let me know 🙂

    #1737755
    Davide

    Hi Leo, thank you.
    not sure about that https://docs.generatepress.com/article/generate_hook_element_display/ but I’ll check it out on Monday.

    I’m trying to display a “generate_menu_bar_items” hook on pages which are using the template (let’s say) layout-example.php.

    Maybe this could be achieved directly in the template (layout-example.php) itself..

    thanks.
    Have a nice weekend
    David

    #1738265
    Leo
    Staff
    Customer Support

    Perhaps something like this?

    add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
        if ( 10 === $element_id && is_page_template( 'layout-example.php' ) ) {
            $display = true;
        }
    
        return $display;
    }, 10, 2 );
    #1741417
    Davide

    Hi Leo,
    perfect, thanks!

    David

    #1741535
    Leo
    Staff
    Customer Support

    No problem 🙂

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