简体   繁体   中英

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:

[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. 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]");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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