【发布时间】:2016-06-22 06:45:22
【问题描述】:
我最近更新了我的旧(3.0.1 版)wordpress 博客,里面有很多带有图片的帖子。此外,我的博客有一个脚本,可以查找页面内容中的所有图像并将其替换为图像轮播。旧帖子一切正常,但是当我创建新帖子时,轮播不起作用。我注意到代码的新 wordpress 版本以另一种方式显示。在这个轮播上,我的脚本输出不起作用。
有没有办法让简码不被改变。比如 a was 在旧版本中。
旧 wordpress 版本简码:
[caption id="attachment_27534" align="alignnone" width="450" caption="Caption text"]<a href="image.jpg"><img class="size-full wp-image-27534" title="" src="gailius.jpg" alt="" width="450" height="370" /></a>[/caption]
新版本将此短代码更改为
[caption id="attachment_27534" align="alignnone" width="450"]<a href="image.jpg"><img class="size-full wp-image-27534" title="" src="image.jpg" alt="" width="450" height="370" /></a>Caption text[/caption]
编辑:
我找到了生成简码的函数
function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
if ( empty($caption) || apply_filters( 'disable_captions', '' ) )
return $html;
$id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
if ( ! preg_match( '/width=["\']([0-9]+)/', $html, $matches ) )
return $html;
$width = $matches[1];
$caption = str_replace( array("\r\n", "\r"), "\n", $caption);
$caption = preg_replace_callback( '/<[a-zA-Z0-9]+(?: [^<>]+>)*/', '_cleanup_image_add_caption', $caption );
// Convert any remaining line breaks to <br>.
$caption = preg_replace( '/[ \n\t]*\n[ \t]*/', '<br />', $caption );
$html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
if ( empty($align) )
$align = 'none';
$shcode = '[caption id="' . $id . '" align="align' . $align . '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]';
return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
}
如何从我的functions.php修改这部分?
$shcode = '[caption id="' . $id . '" align="align' . $align . '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]';
我被替换了所有的功能
add_filter( 'image_add_caption', 'my_image_add_caption');
function my_image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
但没有任何改变
【问题讨论】: