- This topic has 10 replies, 3 voices, and was last updated 1 year ago by
Fernando.
-
AuthorPosts
-
July 30, 2022 at 11:52 pm #2298586
ER
Hi. I use a hook and element on my categories on top of categories and on mainpage.
When I go to second category page with posts the element hook is still there. Is it possible to have the hook element only on mainpage or
top of 1st category page. How do I disable element for other category pages e.g. 2 3 4 and so on.July 31, 2022 at 6:09 am #2298748David
StaffCustomer SupportHi there,
you can use a PHP Snippet like so:
add_filter( 'generate_element_display', function( $display, $element_id ) { if ( 99 === $element_id && is_paged() ) { $display = false; } return $display; }, 10, 2 );
You need to change the
99
to the ID of your Element ( which can be found in the Browser URL when editing the element ).How to add PHP:
https://docs.generatepress.com/article/adding-php/July 31, 2022 at 6:10 am #2298750ER
Ok, so if I only want element on 1st page or mainpage of a category, it’s the code I use?
July 31, 2022 at 6:51 am #2298791ER
It worked, thanks. Can I do like this:
add_filter( ‘generate_element_display’, function( $display, $element_id ) {
if ( 3137 === $element_id && is_paged() ) {
$display = false;
}return $display;
}, 10, 2 );*3137,3032,2352,2523,2523
Can I replace 3137 with this: 3137,3032,2352,2523,2523 if I want the function work for several elements?
July 31, 2022 at 6:55 am #2298796David
StaffCustomer SupportTry this:
add_filter( 'generate_element_display', function( $display, $element_id ) { $your_element_ids = array( 3137, 3032, 2352, 2523, 2523 ); if ( in_array( (int)$element_id, $your_element_ids ) && is_paged() ) { $display = false; } return $display; }, 10, 2 );
Just update the
$your_element_ids = array()
valuesJuly 31, 2022 at 7:22 am #2298831ER
Didn’t work for me, you are sure this is correct?
July 31, 2022 at 7:24 am #2298833David
StaffCustomer SupportOh my – sorry i pasted in the wrong code …. i fixed it here:
https://generatepress.com/forums/topic/i-want-only-element-on-mainpage/#post-2298796
give that a try
July 31, 2022 at 7:29 am #2298840ER
Works now! Thanks a lot.
July 31, 2022 at 7:39 am #2298845David
StaffCustomer SupportGlad to be of help
September 5, 2022 at 12:13 pm #2334170ER
I use a hook and element on my categories on top of categories and on main page.
When I go to second category page with posts the element hook is still there. Is it possible to have the hook element only on main page or
top of 1st category page. How do I disable element for other category pages e.g. 2 3 4 and so on.Hi. I have the same question as above but I would like to implement it for tags, can you provide me with the code for it?
September 5, 2022 at 6:35 pm #2334318Fernando Customer Support
Hi ER,
Will the Element be displaying on all categories archives- just the first page though?
-
AuthorPosts
- You must be logged in to reply to this topic.