filters - How to modify image caption in posts?

I am trying to modify the caption of images in posts by filtering img_caption_shortcode, and then displaying the content

I am trying to modify the caption of images in posts by filtering img_caption_shortcode, and then displaying the content using the_content(). I want to add bylines/credit on images, so I have created two fields in ACF that should be added inside the <figcaption> on all my posts. Basically I want to do what is description in the blog.

So from this:

<figcaption>
So this is a caption that describes the image.
</figcaption>

To this:

<figcaption class="post-thumbnail-caption">
So this is a caption that describes the image.
<span class="wp-block-image-byline">Photo: Gregor Gregson</span>
</figcaption>

I have tried just doing it as simple as possible, but I can not get it to work. Nothing happans/changes with the following code in my functions.php (I did first try the whole code from the example in the blog linked above).

add_filter( 'img_caption_shortcode', 'my_img_caption_shortcode', 10, 3 );
 
function my_img_caption_shortcode( $output, $attr, $content ) {
    $output = 'test';
    return $output;
 
}

Any ideas on what I could be doing wrong?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744059885a4551585.html

相关推荐

  • filters - How to modify image caption in posts?

    I am trying to modify the caption of images in posts by filtering img_caption_shortcode, and then displaying the content

    9天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信