How do i make the feature image default to the first image the

For blogs or marketpress i want the first image on the page to be assumed to be the featured image, unless it is overwritten by manually selecting a different featured image.

Any ideas? Plug ins? Something like this?

  • PC
    • WPMU DEV Initiate

    Hey there Dev4,

    Thanks for posting on the forums.

    I did some research and came across :

    You can add the below code to your theme’s functions.php (or create your own plugin) :

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

    Please let me know how that goes :slight_smile:

    Cheers, PC

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.