Hi there,
you can add a DIV with one of the GP hide-on-* classes around your shortcode eg.
add_action('generate_after_entry_title', function(){
if( is_single() ){
echo '<div class="hide-on-desktop">';
// Nur in Beiträgen zu sehen
echo do_shortcode(‘Text/URL’);
echo '<div>';
}
});
This is a CSS method to “hide” the HTML NOT remove it.
The alternative is to use the wp_is_mobile() function:
https://developer.ww.wp.xz.cn/reference/functions/wp_is_mobile/
Example:
add_action('generate_after_entry_title', function(){
if( is_single() && !is_wp_mobile() ){
echo '<div class="hide-on-desktop">';
// Nur in Beiträgen zu sehen
echo do_shortcode(‘Text/URL’);
echo '<div>';
}
});
Here we use ! NOT mobile. And we keep the DIV with the hide-on class. As wp_is_mobile() is a server side function it may. not work if the page is cached.
Thx for your great and fast support.
I still have a small problem. Depending on which hook I choose, the layout is displayed incorrectly and the posts are no longer displayed … I’m using the following code:
add_action('generate_before_main_content',function(){
echo '<div class="hide-on-desktop">';
// Überall zu sehenn
echo do_shortcode('URL & Text');
echo '<div>';
});
It looks like https://gyazo.com/fbbd05910f1eb045331682ba96d5989b instead of https://gyazo.com/a6396fed420838ff6eb6c48a702c841e.
-
This reply was modified 3 years, 2 months ago by
Chigolo.
Aah sorry the closing div is incorrect.
This: echo '<div>'; should be echo '</div>';
Small cause – big effect … 😉 Now it’s working. Thx a a lot!