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 ) ) return; ?> <section> <p class="text-center muted"> <?php echo strip_tags(apply_filters ('the_excerpt', $post->post_content)) ?> </p> </section> <?php }
8 thoughts on “Displaying the image descriptions on attachment page”
Howdy all and many thanks Nicolas for the fix, worked great with one caveat: html in the text has no impact on the way the text displays. If I remove the closing bracket as in your last reply to Azkajune, it gives me a parsing error. Any ideas? cheers, G.
thank you perfect blog 😉
Hi Azkajune,
In the snippet, replace this line :
By this one :
This should now display html tags.
Hope this helps
I’ve tried this snippet only it appeared as a plain text. The bullets won’t shown up. There’s no box and the appearance wasn’t good.
Please just update Customizr theme so that the image description would appear on attachment page like it used to.
Doesnt work for me. If i add this to the bottom of the functions.php then i get this error message:Parse error: syntax error, unexpected ‘}’ in /homepages/30/d393651867/htdocs/store/wp-content/themes/shoppress/functions.php on line 535
Any ideas?
Hi Dinch,
This is a very common php error.
http://www.phpreferencebook.com/misc/php-errors-common-mistakes/
More about diagnosing problems in Customizr : http://www.presscustomizr.com/customizr/diagnosing-problems-customizr/
Thanks
Works great!
I found this (http://justintadlock.com/archives/2011/02/02/creating-a-custom-functions-plugin-for-end-users) that explains how you can turn this into a plugin.
I was wondering if the description could be centered under the image. it currently shows the image centered on the page and the description to the left.
I am also trying to get the description to have a space between the image and description.
I am fiddling with the code but haven’t got it figured out yet.
Glad I found this!
Thanks for this feedback Dwayne