• Hello. I would like to know if it’s possible to add the meta description from an image to the image attachment.

    I tried to look at other themes such Koji and Eksell where descriptions are added with captions, but I’m not at all php expert and didn’t success.

    Any ideas ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Theme Author Anders Norén

    (@anlino)

    Hi @wpsoup,

    It’s possible, but you’re going to have create a child theme and add the output of the caption by copying over the singular.php file to the child theme and modify it there. You can use this code to output the caption (copied from Eksell):

    <?php if ( $caption = get_the_post_thumbnail_caption() ) : ?>
    	<figcaption><?php echo $caption; ?></figcaption>
    <?php endif; ?>

    You’ll probably need to add some styling to it as well.

    — Anders

    Thread Starter wpsoup

    (@wpsoup)

    Hello @anlino. Thanks for your reply and thank you a lot for your great themes.

    Your answer didn’t solve my problem but permits to progress.

    In fact my aim was to add the description data from an image (not the caption data), when you opened it from a gallery post made by wordpress editor, which link to attachment page.

    I don’t want bother you on how I concluded this but if I erase image.php from Fukasawa theme, description data from image attachment page appears by defaut.

    So I add the following code to a child image.php and it works :

    <?php 
    if ( $post_format == 'video' && isset( $content_parts ) ) { 
    $content = $content_parts['extended'] ? $content_parts['extended'] : '';
    $content = apply_filters( 'the_content', $content );
    echo $content;
    } else {
    the_content();
    }
    
    if ( ! is_single() ) {
    edit_post_link( __( 'Edit post', 'fukasawa' ), '<p>', '</p>' );
    }
    
    ?>

    I don’t know if I paste uncessary lines of code, but there is something inside this which missing inside Image.php to display description data.

    • This reply was modified 3 years, 7 months ago by wpsoup. Reason: page formatting
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Insert image description inside image.php’ is closed to new replies.