Archived topic
Reusable block filter for desktop / mobile
9 replies · Started by Bernhard on September 15, 2021
Hello,
referring to the function that Ying indicated me here to display block elements on desktop,
if ( wp_is_mobile() ) {
add_filter( 'generate_block_element_display', function( $display, $element_id ) {
$id_targets = array(211, 212, 213);
if ( in_array($element_id, $id_targets )) {
$display = false;
}
return $display;
}, 10, 2 );
}
I would like to know how to apply this for reusable blocks.
Thank you.
Hi Bernhard,
The idea is basically the same assuming you're adding the reusable block inside a Block Element.
The filter applies to the post type gp_elements block so its contents (ex. reusable block) is affected when the filter is applied.
That said, are you trying to apply the filter on a Block Element's content (reusable block) ONLY? If so, it's not possible with this code. And I don't think WordPress core has a filter for it like how Tom did for gp_elements.
Note: Reusable blocks are WordPress core feature.
Hi Elvin,
thank you for the explanation.
Is it possible to place a gp block element in the content of a post/page? Maybe with a custom hook or a shortcode?
Is it possible to place a gp block element in the content of a post/page? Maybe with a custom hook or a shortcode?
It's definitely possible but it's going to be tedious and inefficient if the Block element is a template-like thing where it has to appear on ALL posts.
Here's a portable hook shortcode. - https://generatepress.com/forums/topic/inserting-custom-php-html-into-gutenberg-or-site-container/#post-1713422
Great :) You made my day! Thank you.
This makes it much easier to automate the page. :) :) :)
The strange thing is, that at the beginning also the connection between the languages worked. Now, after some updates and cache purge it works no more.
The strange thing is, that at the beginning also the connection between the languages worked. Now, after some updates and cache purge it works no more.
Not exactly sure what you mean. Did you mean the translations stopped working?
If that's the case, it seems like a different topic. Can you open a new one for it? To avoid convoluting this one. Thank you. :D
Something is caused by the cache and I try to find the best settings. Actually it needs a while to have the correct layout in place. Thank you :)
Something is caused by the cache and I try to find the best settings. Actually it needs a while to have the correct layout in place. Thank you
Sounds like a performance issue. Have you sorted it out?
You can open a new topic for it if you need any help. :D
Yes, I've disabled the WP Rocket additional plugin "Set Tablets As Mobile" and I have set the Generateblocks CSS to inline.
Nice one. Thanks for letting us know. Glad you got it sorted. :D