shortcode block calling an image showing in header in FSE themes

[ad_1]

Hello, I meet a problem I cannot explain. I’ve created several shortcodes to insert content in single content and, if text through shortcodes shows at the good place, an image shows… before in the header, whatever I place the shortcode.
Tested on two different FSE themes.

Here is the code in the shortcode

// shortcode pour fse-alternative
function shortcode_fsealternative(){
global $post ;
        $alternativeimage = get_post_meta($post->ID, 'alternative_image', true);

        if (!empty($alternativeimage)) {
        $urlcmm='https://xxx/blog/wp-content/uploads/alternative/'.$alternativeimage;
        }
        else {
        $urlcmm='https:/xxx/blog/wp-content/uploads/images-site/click-x-640.png';
        if ( !is_single() ) {
        $urlcmm='https://xxx/blog/wp-content/uploads/images-site/click-x-home.png';}
        
        }
echo '<figure class="wp-block-post-featured-image"><img src="' . $urlcmm . '" /></figure>';
      }
add_shortcode('fsealternative', 'shortcode_fsealternative');

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer