- This topic has 8 replies, 5 voices, and was last updated 3 years, 7 months ago by
David.
-
AuthorPosts
-
June 5, 2020 at 1:53 pm #1316133
stephen
Do you know if there is a way to disable Elements from the AMP pages? There is exclude, I see that but AMP isn’t an option. reason I ask is because I got elements showing up that I’d use for the regular site on the AMP themed site.
June 6, 2020 at 9:40 am #1317046Tom
Lead DeveloperLead DeveloperHi there,
You won’t find this in the Display Rules, but you can use a filter depending on the Element:
https://docs.generatepress.com/article/generate_header_element_display/
https://docs.generatepress.com/article/generate_hook_element_display/
https://docs.generatepress.com/article/generate_layout_element_display/For example:
add_filter( 'generate_hook_element_display', function( $display, $element_id ) { if ( 123 === $element_id ) { // Update ID to match your Element. if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) { $display = false; } } return $display; }, 10, 2 );October 4, 2022 at 2:19 pm #2363305Cheryl
Hi,
I’m trying the above code to hide an element on non-amp, but it’s not working. I do have the element ID in the code. Although, I am trying to hide a block element attached to the generate_menu_bar_items hook.This is what I’ve tried, in addition to the above:
add_filter( ‘generate_element_display’, function( $display, $element_id ) {
if ( 65659 === $element_id ) { // Update ID to match your Element.
if ( function_exists( ‘is_amp_endpoint’ ) && is_amp_endpoint() ) {
$display = false;
}
}return $display;
}, 10, 2 );Thanks
CherylOctober 4, 2022 at 2:33 pm #2363316Ying
StaffCustomer SupportI’m trying the above code to hide an element on non-amp
Hi Cheryl,
The code you are using is to do the opposite, it hides the element on AMP pages. Try the below code instead:
add_filter( 'generate_hook_element_display', function( $display, $element_id ) { if ( 65659 === $element_id ) { // Update ID to match your Element. if ( ! function_exists( 'is_amp_endpoint' ) && ! is_amp_endpoint() ) { $display = false; } } return $display; }, 10, 2 );October 5, 2022 at 8:13 am #2364250Cheryl
Hi. Thanks for the quick response. But the code didn’t work. It didn’t successfully hide the element on non-AMP.
I also tried it with generate_element_display as this is a block element with a hook. I also tried changing false to true.
I’ve tried it with a couple of element, but still cannot hide an element on non-amp.
October 5, 2022 at 9:07 am #2364308Cheryl
…though I’ve found another way around this particular thing — I inserted it as an ad instead and had it just show on AMP.
October 5, 2022 at 10:42 am #2364422Tom
Lead DeveloperLead DeveloperHi there,
Just for reference, this code should do it in the future:
add_filter( 'generate_element_display', function( $display, $element_id ) { if ( 65659 === (int) $element_id ) { // Update ID to match your Element. if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) { $display = false; } } return $display; }, 10, 2 );October 6, 2022 at 5:39 am #2365109Cheryl
Hi,
When I used that, it hid the item on the AMP page instead of on the non-AMP page. I’m trying to find a way to hide something on non-AMP so it only shows on AMP.October 6, 2022 at 8:10 am #2365377David
StaffCustomer SupportHi there,
try this:
add_filter( 'generate_element_display', function( $display, $element_id ) { if ( 65659 === (int) $element_id ) { // Update ID to match your Element. if ( function_exists( 'is_amp_endpoint' ) && !is_amp_endpoint() ) { $display = false; } } return $display; }, 10, 2 );The change is subtle from:
is_amp_endpoint()to!is_amp_endpoint()which will check if it is NOT an AMP page. -
AuthorPosts
- You must be logged in to reply to this topic.