[Resolved] Element/Hook

Home Forums Support Element/Hook

  • This topic has 5 replies, 2 voices, and was last updated 1 year ago by David.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1012201
    Florian

    Hi Tom,

    I’ve added some Text as Element/Hook on my Frontpage. Right now I saw it is also displayed on /Page/2/, /page/3/ etc. – so it’s duplicate Content to my bad. Any idea how I can restrict it to be shown only on the Frontpage and exclude /page/x/?

    It’s display rule is “frontpage”, I have no useable exclude found.

    Thanks

    #1012294
    David
    Staff
    Customer Support

    Hi there,

    you can use this filter to remove the element from paged content:

    add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
        if ( 10 === $element_id && is_paged() ) {
            $display = false;
        }
    
        return $display;
    }, 10, 2 );

    Replace the 10 with the ID of the Element you wish to remove. ID can be found by editing element and checking the URL.

    #1012330
    Florian

    Hi David,

    thanks a lot, it’s working. But 1 question: at the end “}, 10, 2 );” – is the 10 also the ID? what is the 2? And how I can add 2 IDs at the same time, because I want to hide 2 elements.

    Thanks in advance

    #1012395
    David
    Staff
    Customer Support

    The 10 is the Hooks Priority – and you should leave this as 10.
    The 2 is the number of parameters used in the Filter. Again this should be left as 2.

    Just make a duplicate of the same code for your second element and change the ID.

    #1012420
    Florian

    Thanks!

    #1012423
    David
    Staff
    Customer Support
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.