是的,可以操纵the_content
.
您想要做的最简单的方法是在您的functions.php 文件中添加一个过滤器。
我刚刚从 Codex 中提取了此内容并进行了一些修改,以便您可以了解我正在谈论的要点。
add_filter( 'img_caption_shortcode', 'my_img_caption_shortcode', 10, 3 );
function my_img_caption_shortcode( $output, $attr, $content ) {
$attr = shortcode_atts( array(
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => ''
), $attr );
if ( 1 > (int) $attr['width'] || empty( $attr['caption'] ) ) {
return '';
}
if ( $attr['id'] ) {
$attr['id'] = 'id="' . esc_attr( $attr['id'] ) . '" ';
}
return '<div ' . $attr['id']
. 'class="wp-caption ' . esc_attr( $attr['align'] ) . '" '
. 'style="max-width: ' . ( 10 + (int) $attr['width'] ) . 'px;">'
. do_shortcode( $content )
. '<p class="wp-caption-text">' . $attr['caption'] . '</p>'
. '</div>';
}
然后您可以做的是,如果您看到$attr['caption']
,您可以修改您想要的方式。所以你可以这样做:get_the_title($attr['id'])
添加标题或get_post_meta($attr['id'], '_wp_attachment_image_alt', TRUE);
获取图像替代。
为了使事情变得更容易,如果您想获取特定附件的所有详细信息,您可以使用类似的函数this https://wordpress.stackexchange.com/questions/125554/get-image-description然后得到你想要的任何东西。
以下是将标题添加到说明中的示例。格式为“标题-说明文字”
. '<p class="wp-caption-text">' . get_the_title($attr['id']) . " - " . $attr['caption'] . '</p>'
代码参考链接:https://developer.wordpress.org/reference/hooks/img_caption_shortcode/ https://developer.wordpress.org/reference/hooks/img_caption_shortcode/