我的Wordpress帖子中有以下字段设置的图像:
标题:此字段包含要显示在图像下方的实际图像标题。
描述:此字段包含带有属性源链接的照片信用。
我需要将这两个值显示在图像的正下方,如下所示:
从@toscho的精彩回答中获得线索this 问题,我尝试了此功能:add_shortcode(\'wp_caption\', \'img_caption_add_description\');
add_shortcode(\'caption\', \'img_caption_add_description\');
function img_caption_add_description($attr, $content = null)
{
$post_id = str_replace(\'attachment_\', \'\', $attr[\'id\']);
$img = get_post((int)$post_id);
if (is_a($img, \'WP_Post\')) {
$attr[\'caption\'] = $img->post_content;
}
return img_caption_shortcode($attr, $content);
}
正如您在屏幕截图中所看到的,该函数除了去掉所有超链接外,其他功能都做得很好。我需要他们!有没有办法修改上述功能,使其尊重链接?例如,在上述示例中,文本“Amit Schandillia”和“CC BY-SA 3.0”都是超链接。我在我的描述字段中有如下链接:Photo credit: <a href="" target="_blank" rel="nofollow">Amit Schandillia</a> licensed <a href="" target="_blank" rel="nofollow"><i class="fa fa-creative-commons"></i> BY-SA 3.0</a>
如何确保<a>
标签在贴子页面上呈现时是否保持不变?