• Resolved kiaseven

    (@kiaseven)


    Hi,

    I want to be able to manipulate the captions on atlasandboots.com. For example, the in-post image here: https://www.atlasandboots.com/gift-of-bilingualism.

    To simplify, say I want to add a string that says (Image: Atlas & Boots) after every existing caption on the site.

    I thought I could go to image.php and then edit the bold line into the following piece of code, but it doesn’t work.

    <?php if ( ! empty( $post->post_excerpt ) ) : ?>
    <div class=”entry-caption”>
    <?php the_excerpt(); ?>
    <p>(Image: Atlas & Boots)</p>
    </div>
    <?php endif; ?>

    I’ve tried <?php echo “Image: Atlas & Boots”; ?> as well but it doesn’t work. I can’t figure out where the captions are being added in the template. Any help would be much appreciated.

    Thank you,

    Kia

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Kathryn Presner

    (@zoonini)

    The wp-caption class is automatically added by WordPress core – it’s not something within the theme.

    You could try adding your text with custom CSS — something like this:

    .wp-caption::after {
      content: "Image: Atlas & Boots";
      display: block;
      text-align: right;
      font-size: 12px;
    }

    Don’t edit the theme files directly, otherwise your changes will be overwritten every time the theme is updated.

    An easy way to add custom CSS is to use the CSS editor included in the Customizer as of WordPress 4.7. Head to Appearance > Customize > Additional CSS to add your custom CSS.

    Let me know how it goes.

    Thread Starter kiaseven

    (@kiaseven)

    Hi Kathryn,

    Thank you for this. I may go the plugin route as the text I need appended is dynamic. I created a custom field (image_credit) and wanted that to be appended to the caption on a case by case basis so the CSS option won’t work. (Sorry if my question led you down the wrong path; I used a static example for simplicity to figure out where to access the caption data.)

    The plugin Media Credit doesn’t quite do this (it outputs the caption above rather than after the caption) but I think this is better than messing with the core functionality.

    Thank you for your help. I’ll close this thread.

    Kia

    Moderator Kathryn Presner

    (@zoonini)

    Hi Kia – ah, thanks for clarifying that the captions won’t all be the same, I definitely didn’t realize that. Good luck with the plugin route!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to access caption data’ is closed to new replies.