Last active
October 3, 2023 14:35
-
-
Save Oscar-Abad-Folgueira/82e571b8627625fe59a23937c93f12a9 to your computer and use it in GitHub Desktop.
Comprobar si el post tiene asignada imagen destacada y mostrarla en caso afirmativo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @snippet WordPress Snippet: Comprobar si el post (entrada) tiene asignada imagen destada. Si es así, motrarla (medium) | |
* @author Oscar Abad Folgueira | |
* @author_url https://www.aprendeinformaticaconmigo.com | |
* @snippet_url https://www.aprendeinformaticaconmigo.com/wordpress-comprobar-la-entrada-post-tiene-asignada-una-imagen-destacada-y-si-es-asi-mostrarla-en-tamano-medium | |
*/ | |
function oaf_check_has_featured_image(){ | |
// comprobar si es un singe de tipo post | |
if( is_singular( 'post' ) ){ | |
// Comprobar si tiene imagen destacada asignada | |
if(has_post_thumbnail()){ | |
// si la tiene, mostrarla a tamaño 'medium' | |
echo get_the_post_thumbnail(get_the_ID(), 'medium'); | |
} else { | |
echo "Pues NO. Parece que tenga imagen"; | |
} | |
} | |
} | |
add_action( "template_redirect", "oaf_check_has_featured_image" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment