简体   繁体   English

WordPress,在简码中解析简码

[英]WordPress, Parse Shortcode within Shortcode

I'm working on a site for a client that runs a social ransom style blog. 我正在为一个运行社交赎金风格博客的客户创建一个网站。 This is where the user has to click one of the social media buttons to get access to the content. 这是用户必须单击社交媒体按钮之一才能访问内容的地方。

However, she is now going to use the OnePress Social Locker Plugin for wordpress which works by wrapping the content in specific tags, like so: 但是,她现在将对Wordpress使用OnePress Social Locker插件,该插件通过将内容包装在特定标签中来工作,如下所示:

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

At the moment she already has her own custom shortcode in place which works like this: 目前,她已经有自己的自定义简码,其工作方式如下:

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

The problem is that she has over 2,300 pages on her blog and to change every single one indv. 问题是她在博客上拥有2300多个页面,并且要更改每一个indv。 through the dashboard will take ages and this is not a by the hour pay contract. 通过仪表板将需要很长时间,这不是按小时支付的合同。

I thought that I would be able to pass the current shortcode into the new one like so: 我认为我可以将当​​前的简码传递给新的简码,如下所示:

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' );

However that just outputs 但是那只是输出

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

Has anyone got any ideas how to parse this second shortcode within a shortcode? 有谁知道如何在简码中解析第二个简码?

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM