Support » Plugins » Hacks » Display Title as Caption in WP Gallery

  • Is there a way.. coding or plugin.. to display the image “Title” as the caption while using the standard WP Gallery?

Viewing 8 replies - 1 through 8 (of 8 total)
  • esmi


    Forum Moderator

    Not without completely rewriting the gallery shortcode as part of your theme.

    hmmmm.. when you upload an image, the title automatically is set based on the filename. wish there was a way for the caption to be auto set as well.

    You can set the caption to the title using the following.

    add_filter('attachment_fields_to_edit', 'image_caption_to_title', 11, 2 );
    function image_caption_to_title( $form_fields, $post ) {
    	if ( substr( $post->post_mime_type, 0, 5 ) == 'image' ) {
    		$form_fields['post_excerpt']['value'] = $post->post_title;
    		//$form_fields['post_excerpt']['input'] = 'hidden';
    	return $form_fields;

    You can also hide the caption field by changing //$form_fields['post_excerpt']['input'] = 'hidden'; for $form_fields['post_excerpt']['input'] = 'hidden';.

    All it will do is set the default value of the caption to that of the title(it doesn’t stop a user changing it, but you can hide the field to prevent it as i mentioned above).

    Hope that helps..

    Mark, thank you very much’
    i hate to sound like a newb, but which file do i add this too? functions.php?

    nevermind, it worked great, thank you!
    now if only there was a way to get it to work retroactively to my existingn uploads, hehe

    Les Bessant


    keeper of the Tiggers

    Mark, you just saved what’s left of my sanity – this is exactly what I’ve been searching for. Thanks 🙂

    I am a newbie to WP ~ what is the answer to where the code gets added?

    Is there a plug-in that can modify existing images in the media library?

    Thanks in advance.

    Place that code into your functions.php file, save it.
    Upload an image, after it’s done crunching Save it again.. your title and caption will end up as whatever your title was.

    I’ve gotten into the habit of simply naming my images the same as I want it captioned, works great.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Display Title as Caption in WP Gallery’ is closed to new replies.