Prelevare la prima immagine di un post wordpress
dic 21
A volte, per esigenze grafiche, si ha la necessità di isolare le immagini del nostro theme wordpress, e manipolarle come ci piace.
Questa funzione è realizzabile. Vi posto il codice :
function get_first_image($post){ preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); $firstimage = $matches[1][0]; return $firstimage; }
Per renderla visibile in tutto il theme wordpress, basta inserirla nella pagina functions.php