function set_featured_image_from_content( $post_id ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; if ( wp_is_post_revision( $post_id ) ) return; if ( has_post_thumbnail( $post_id ) ) return; $content = get_post_field( 'post_content', $post_id ); if ( ! $content ) return; $image_id = null; // Cerca immagini nel blocco galleria if ( preg_match_all( '/"id":(\d+)/', $content, $gallery_matches ) ) { foreach ( $gallery_matches[1] as $id ) { if ( wp_attachment_is_image( $id ) ) { $image_id = $id; break; } } } // Se non trovata in galleria, cerca immagini singole nel contenuto if ( ! $image_id ) { if ( preg_match_all( '/]+wp-image-(\d+)[^>]*>/i', $content, $img_matches ) ) { foreach ( $img_matches[1] as $id ) { if ( wp_attachment_is_image( $id ) ) { $image_id = $id; break; } } } } // Se non trovata, cerca per URL if ( ! $image_id ) { if ( preg_match_all( '/]+src=[\'"]([^\'"]+)[\'"][^>]*>/i', $content, $url_matches ) ) { foreach ( $url_matches[1] as $url ) { $id = attachment_url_to_postid( $url ); if ( $id ) { $image_id = $id; break; } } } } // Se trovata imposta come immagine in evidenza if ( $image_id ) { set_post_thumbnail( $post_id, $image_id ); return; } // Fallback casuale $fallback_ids = array( 45835, 45834, 45833, 45831, 45832 ); $random_id = $fallback_ids[ array_rand( $fallback_ids ) ]; set_post_thumbnail( $post_id, $random_id ); } add_action( 'save_post_post', 'set_featured_image_from_content', 10, 1 );
Skip to content Skip to sidebar Skip to footer

MORIONDO A SEGNO A VINCENNES

Il biondo Moriondo, made in casa Smorgon ma ceduto in questi giorni alla scuderia milanese di Chirstian Rizzo, ha più volte dimostrato di essere particolarmente adatto alla pista di Vincennes e con i nuovi colori è andato a segno sabato 24 marzo in una prova europea sui 2850 metri: bottino di 25.000 euro, niente male!

Rispondi

Scopri di più da Ippodromo di Vinovo

Abbonati ora per continuare a leggere e avere accesso all'archivio completo.

Continua a leggere