是的,可以操纵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 之类的函数,然后获取您想要的任何内容。
这是一个将标题添加到标题的示例。格式为“Title - Caption”
. '<p class="wp-caption-text">' . get_the_title($attr['id']) . " - " . $attr['caption'] . '</p>'
代码参考链接:https://developer.wordpress.org/reference/hooks/img_caption_shortcode/