简体   繁体   中英

Put php logic function inside wordpress Shortcode

I have this code that displays an content to to users who have an paid subscribtion:

echo do_shortcode('[ihc-hide-content ihc_mb_who="5,7"] MY CONTENT HERE [/ihc-hide-content])

But I want to display inside this shortcode where it says MY CONTENT HERE, an logical function, like this:

if ( $a = $b ) {    echo ($c);    }

There is possibile to do this in some way? PS I have made another shortcode, and put him inside like this:

do_shortcode('[ihc-hide-content ihc_mb_who="5,7"].do_shortcode('[my_shortcode]').[/ihc-hide-content])

But the 1st shortcode is not hide the content of 2nd shortcode. Any help will be apreciated, ans sorry for my bad english!

If you're using an Enclosing Shortcode you should just be able to add the shortcode as a string to your do_shortcode() function. do_shortcode() will search the content that's passed to it and parse out any and all shortcodes that it's able to. Depending on how the ihc-hide-content shortcode is set up, it may not work quite properly, but you can get around that as well.

First and foremost, I would try just passing a single shortcode string to it:

do_shortcode( '[ihc-hide-content ihc_mb_who="5,7"][my_shortcode][/ihc-hide-content]' );

If that doesn't work (in all honesty, it should) - you can try and generate the output from my_shortcode into an Output Buffer like so:

// Turn on Output Buffering
ob_start();

// Output your shortcode
do_shortcode( '[my_shortcode]' );

// Turn off Output Buffering, and grab the content as a variable
$my_shortcode_output = ob_get_clean();

// Pass that complete output to the other shortcode
do_shortcode( '[ihc-hide-content ihc_mb_who="5,7"]'. $my_shortcode_output .'[/ihc-hide-content]' );

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