Support » Fixing WordPress » Cover image automatically

  • Resolved Tony Franco

    (@tony-franco)


    Dear Sirs,

    Please, is it possible to automatically set the cover image when adding it, with the featured image already setted?

    I ask that because i have created a pattern block with a cover image, and if i change the featured image, could also change the cover image.

    Regards,
    Tony

    • This topic was modified 2 years, 6 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
Viewing 3 replies - 1 through 3 (of 3 total)
  • You have to code that functionality. Right now, both work independently

    Thread Starter Tony Franco

    (@tony-franco)

    Hi @a2hostingrj

    Thanks by your reply!

    I will look a way to do it.

    Regards,
    Tony

    Thread Starter Tony Franco

    (@tony-franco)

    Hi @a2hostingrj

    Please, i have created these shortcodes for post thumbnail informations:

    add_shortcode('thumbnail_id', 'thumbnail_with_caption_shortcode_3');
    function thumbnail_with_caption_shortcode_3($atts) {
        global $post;
    
    	$thumbnail = get_the_post_thumbnail($post->ID);
    	
        $thumbnail_id = get_post_thumbnail_id();
    	return $thumbnail_id;
    }
    
    add_shortcode('thumbnail_url', 'thumbnail_with_caption_shortcode_2');
    function thumbnail_with_caption_shortcode_2($atts) {
        global $post;
    
    	$thumbnail = get_the_post_thumbnail($post->ID);
    	
    	$thumbnail_url = wp_get_attachment_url( get_post_thumbnail_id( $id ) );
    	
        //$thumbnail_url = get_permalink(get_post_thumbnail_id());
    	return $thumbnail_url;
    }
    
    add_shortcode('thumbnail_caption', 'thumbnail_with_caption_shortcode');
    function thumbnail_with_caption_shortcode($atts) {
        global $post;
    
    	$thumbnail = get_the_post_thumbnail($post->ID);
    	
       $thumbnail_id = get_post_thumbnail_id();
    	$thumbnail_caption = get_post($thumbnail_id)->post_excerpt;
    	return $thumbnail_caption;
    }

    And my cover image code is:

    <!-- wp:cover {"url":"[thumbnail_url]","id":[thumbnail_id]} -->
    <div class="wp-block-cover has-background-dim"><img class="wp-block-cover__image-background wp-image-[thumbnail_id]" alt="[thumbnail_caption]" src="[thumbnail_url]" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Escreva o título...","fontSize":"large"} -->
    <p class="has-text-align-center has-large-font-size"></p>
    <!-- /wp:paragraph --></div></div>
    <!-- /wp:cover -->

    Shortcodes for wp:cover are not working, just inside thd div they are working as i saw at Inspect of browser.

    Could you help me understanding why its not working?

    Thanks and Regards,
    Tony

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Cover image automatically’ is closed to new replies.