- This topic has 10 replies, 3 voices, and was last updated 2 years, 1 month ago by Fernando.
-
AuthorPosts
-
July 30, 2022 at 11:52 pm #2298586ER
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 #2298748DavidStaffCustomer 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 #2298750EROk, 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 #2298791ERIt 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 #2298796DavidStaffCustomer 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 #2298831ERDidn’t work for me, you are sure this is correct?
July 31, 2022 at 7:24 am #2298833DavidStaffCustomer 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 #2298840ERWorks now! Thanks a lot.
July 31, 2022 at 7:39 am #2298845DavidStaffCustomer SupportGlad to be of help
September 5, 2022 at 12:13 pm #2334170ERI 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 SupportHi 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.