-
qs304398988
How to set the generatepress element to display within a time period
-
Hi there,
Take a look at David’s suggestion here:
https://generatepress.com/forums/topic/elements-time-based-display-rules/#post-918314If you prefer to go with a custom solution then you will likely need the
generate_element_displayfilter with the time period conditional rule:
https://docs.generatepress.com/article/generate_element_display/Hope this helps 🙂
-
qs304398988
I understand, because I also have a website using the Astra theme, and the similar element function in their theme has an option to set the display time in the custom layout. I don’t know the code, so let’s see if there is a more mature solution here
-
Fernando
Hello there,
David’s suggestion may be the easiest approach.
Codewise, you can try something like this:
add_filter( 'generate_element_display', function( $display, $element_id ) { if ( 100 === $element_id && ( ( get_the_date( 'U' ) > strtotime( '-1 year' ) ) ) { $display = true; } return $display; }, 10, 2 );This will display Element with ID
100after a year for instance. Saw this for reference: https://wordpress.stackexchange.com/questions/383303/check-if-post-was-published-more-than-6-months-ago-using-get-the-date
- You must be logged in to reply to this topic.