WordPress,在Shortcode中解析短代码

时间:2014-07-11 11:54:47

标签: php wordpress plugins shortcode

我在一个网站上为一个运行社交赎金风格博客的客户工作。这是用户必须单击其中一个社交媒体按钮才能访问内容的位置。

然而,她现在将使用OnePress Social Locker插件进行wordpress,它通过将内容包装在特定标签中来实现,如下所示:

[sociallocker] Content Here will Be Locked [/sociallocker]

目前,她已经拥有自己的自定义短代码,其工作方式如下:

[socialLock url="http://example.com" text="Click here to view content"] Content here will be locked [/socialLock]

问题在于,她的博客上有超过2,300页,并且每个人都会改变一次。通过仪表板将需要很长时间,这不是按小时支付合同。

我认为我能够将当前的短代码传递给新的短代码:

function parseShortcode_func( $atts ) {
  $atts = shortcode_atts( array(
      'link' => '',
      'text' => 'default text'
  ), $atts );

  return "[sociallocker] <a href=\"{$atts['link']}\">{$atts['text']}</a> [/sociallocker]";
}
add_shortcode( 'socialLock', 'parseShortcode_func' );

然而,这只是输出

 [sociallocker] Click here to view content [/sociallocker]

有没有人知道如何在短代码中解析第二个短代码?

1 个答案:

答案 0 :(得分:1)

do_shortcode()函数将重新解析输出字符串。

return do_shortcode("[sociallocker] <a href=\"{$atts['link']}\">{$atts['text']}</a> [/sociallocker]");
相关问题