Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello,

    Try to add a featured image in the post to display it. It is the default wordpress behavior that displays the featured image on the blog entry page. Edit a post and upload a featured image in the right sidebar.

    Thread Starter hajo808

    (@hajo808)

    Hello, thanks for the answer. But why doesn’t it work with a picture in a post? I know that it is possible to put a picture on the right side. But I didn’t want to know that. Is this template dependent? If so, how can this be changed?

    I try to explain it again with screenshots.

    That’s how it looks when I make a posting.
    https://www.imagebanana.com/s/1441/axvkRKtO.html

    This is what it looks like in the newsfeed. Where is the picture?
    https://www.imagebanana.com/s/1441/lD0wH5hT.html

    That’s what it looks like when I go straight to the post.
    https://www.imagebanana.com/s/1441/0RwuQweG.html

    Question 2 (independent of question 1)
    If I enter a picture on the right side, it will be shown in the newsfeed. If I then go into the post, it is also displayed there. But I don’t want to see it there anymore. Is that possible?

    To do it, you need to add some codes in the functions.php file or use a plugin for it. Try the below code –

    function auto_featured_image() {
        global $post;
     
        if (!has_post_thumbnail($post->ID)) {
            $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
             
          if ($attached_image) {
                  foreach ($attached_image as $attachment_id => $attachment) {
                       set_post_thumbnail($post->ID, $attachment_id);
                  }
             }
        }
    }
    add_action('the_post', 'auto_featured_image');
    add_action('save_post', 'auto_featured_image');
    add_action('draft_to_publish', 'auto_featured_image');
    add_action('new_to_publish', 'auto_featured_image');
    add_action('pending_to_publish', 'auto_featured_image');
    add_action('future_to_publish', 'auto_featured_image');
    Thread Starter hajo808

    (@hajo808)

    Hello Amit,

    we’re getting closer. If you would now tell me where in function.php the code snippet has to go, I would be super grateful. Unfortunately, I don’t know much about PHP to understand where to insert it.

    And for what problem is the code actually? For the first one I described or the second one?

    Greetings

    You need to install and activate the oceanwp child theme to add the code – https://docs.oceanwp.org/article/90-sample-child-theme

    After activating it, open the functions.php file of the child theme using a code editor and add the code after all other codes.

    Thread Starter hajo808

    (@hajo808)

    Hello,

    I tried to do it the way you described it. Did I do it right? Unfortunately it doesn’t work somehow.

    Video: https://tinyurl.com/yxdrkolw

    Greetings

    The above code should work. You can also use a plugin to achieve it – https://www.ads-software.com/plugins/auto-set-first-image-as-featured/

    Try to upload a featured image using the featured image box in the post editor.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Pictures in posts are not displayed in newsfeed’ is closed to new replies.