Viewing 1 replies (of 1 total)
  • Hi @dmpp,

    Yes, it’s possible. You can try adding a PHP snippet like this:

    add_action('wpsp_before_title', function($settings){
    	global $post, $posts;
        $first_img = '';
        ob_start();
        ob_end_clean();
        $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
        $first_img = $matches [1] [0];
    	
    	//define an image source if there is no first image
    	if(empty($first_img)){
        $first_img = "/images/default.jpg";
      	}
    	
    	echo '<img src=' . $first_img . ' width="' . $settings['image_width'] . '" height="' . $settings['image_height'] . '" />';
    },10 ,1);

    This snippet puts the first image in a post on top of the title.

    Kindly let us know how it goes. ??

Viewing 1 replies (of 1 total)
  • The topic ‘Use first image from post content instead of featured image’ is closed to new replies.