有人熟悉 WordPress 短代码吗?我真的可以用手!我已将以下代码插入到我正在使用的主题的 functions.php 文件中...
function create_slideshow_header($atts, $content = null){
return '<div class="item_heading">'.$content.'</div>';
}
add_shortcode('slideshow_heading', 'create_slideshow_header');
function create_slideshow_white_header($atts, $content = null){
return '<span id="dyn">'.$content.'</span>';
}
add_shortcode('slideshow_heading_white', 'create_slideshow_white_header');
function create_slideshow_content($atts, $content = null){
return '<div class="item_content">'.$content.'</div>';
}
add_shortcode('slideshow_content', 'create_slideshow_content');
现在,我被几个教程引导相信这应该允许我将以下内容插入到 WP 后端的文本编辑器中......
[slideshow_heading]幻灯片标题[/slideshow_heading]
...并且 SLIDESHOW HEADER 文本将包含在适当的 HTML 中...。但它只是将上述内容显示为常规文本。我已经清除了我的缓存等...
有什么我做错了吗?提前致谢!
解决方案
我没有提到我正在使用 page.ly MultiEdit 插件——它使用“自定义字段”来创建额外的可编辑区域。WordPress 不方便地解析自定义字段中的短代码。通常,您可以为每个自定义字段创建一个过滤器,但由于这是一个插件,您只需编辑 multiedit.php 文件,并将第 63 行从
echo $GLOBALS['multiEditDisplay'][$index][0];
至
echo apply_filters('the_content',$GLOBALS['multiEditDisplay'][$index][0]);
只需一点点工作,您就可以将 Wordpress 变成一个真正令人惊叹的 CMS!