Site logo

Archived topic

using hooks on a template page

5 replies · Started by Davide on April 16, 2021

Viewing posts 1–6 of 6

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

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

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 );

Hi Leo,
perfect, thanks!

David

No problem :)

This archived topic is closed to new replies.