Cerchi consigli per migliorare il tuo sito? Vuoi aprire un sito in poco tempo?
Discuti con altri webmaster, chiedi chiarimenti ed opinioni in tutta libertà.
Lo spam verrà cancellato.
da Martina Stella » ven nov 25, 2011 1:03 pm
Ciao a tutti. Vorrei impostare l'immagine di anteprima di un post in Facebook, facendo in modo che prenda la prima del post, ma il codice che ho usato in passato non funziona :(
- Codice: Seleziona tutto
function set_default_image(){
global $post;
$image = str_img_src($post->post_content);
if($image != ""){
echo '<link rel="image_src" href="'. $image . '" />' . "\n";
}
}
add_action('wp_head', 'set_default_image');
function str_img_src($html) {
if (strpos($html, '<img') !== false) {
$imgsrc_regex = '#<\s*img [^\>]*src\s*=\s*(["\'])(.*?)\1#im';
preg_match($imgsrc_regex, $html, $matches);
unset($imgsrc_regex);
unset($html);
if (is_array($matches) && !empty($matches)) {
return $matches[2];
} else {
return false;
}
} else {
return false;
}
}
Il sito è quello in firma....pote aiutarmi ?
http://www.vampirediaries-love.net/
-

Martina Stella
- Senior Member

-
- Messaggi: 354
- Iscritto il: ven gen 16, 2009 3:02 pm
- Località: Treviso, Veneto
-
Torna a Sviluppo Web
Chi c’è in linea
Visitano il forum: Nessuno e 1 ospite