Skip to content

Instantly share code, notes, and snippets.

@javierarcheni
Last active November 9, 2016 23:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javierarcheni/4f950ed8dd26524570deabfce0dd7b54 to your computer and use it in GitHub Desktop.
Save javierarcheni/4f950ed8dd26524570deabfce0dd7b54 to your computer and use it in GitHub Desktop.
Mostrar la leyenda de una imagen destacada en WordPress
<?php $thumb_id = get_post_thumbnail_id();
if ($thumb_id != 0) : // existe imagen destacada
$thumb_url = wp_get_attachment_image_src($thumb_id,'large', true);
$thumbnail_details = get_posts(array('p' => $thumb_id, 'post_type' => 'attachment'));
$titulo = $thumbnail_details[0]->post_title;
$leyenda = $thumbnail_details[0]->post_excerpt;
?>
<figure>
<img class="img-responsive" alt="<?= esc_attr($titulo); ?>" src="<?= esc_url($thumb_url[0]); ?>" />
<?php if (!empty($leyenda)) : ?>
<figcaption>
<p><?= esc_html($leyenda); ?></p>
<figcaption>
<?php endif; ?>
</figure>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment