Displaying the image descriptions on attachment page

⚠️ Code snippets might not be compatible with the latest version of your theme. Always use a child theme to customize your theme, and test your code on a staging website before migrating to production.

The following code will display the description text field of any attachment at the bottom of the attachment page.

Copy and paste this snippet at the very bottom of your functions.php file. (if you are using a child theme, don’t forget to start your functions.php file with <?php )


add_action( '__after_content' ,'my_attachment_description' );

function my_attachment_description() {
global $post;
if ( ( isset($post) && 'attachment' != $post -> post_type) || !is_singular() || empty( $post->post_content ) )
<p class="text-center muted">
<?php echo strip_tags(apply_filters ('the_excerpt', $post->post_content)) ?>


Leave a comment

Your email address will not be published. Required fields are marked *

8 thoughts on “Displaying the image descriptions on attachment page”