[英]Put php logic function inside wordpress Shortcode
我有這個代碼向付費訂閱的用戶顯示內容:
echo do_shortcode('[ihc-hide-content ihc_mb_who="5,7"] MY CONTENT HERE [/ihc-hide-content])
但我想在這個簡碼中顯示我的內容,這是一個邏輯函數,如下所示:
if ( $a = $b ) { echo ($c); }
有可能以某種方式做到這一點嗎? PS我制作了另一個短代碼,然后像這樣把他放在里面:
do_shortcode('[ihc-hide-content ihc_mb_who="5,7"].do_shortcode('[my_shortcode]').[/ihc-hide-content])
但是第一個簡碼不會隱藏第二個簡碼的內容。 任何幫助都將受到贊賞,對不起我的英語不好!
如果您使用的是封閉簡碼,您應該能夠將簡碼作為字符串添加到do_shortcode()
函數中。 do_shortcode()
將搜索傳遞給它的內容並解析出它能夠搜索的任何和所有短代碼。 根據如何ihc-hide-content
簡碼設置,它可能不太正常工作,但你可以避開這一點。
首先,我會嘗試只向它傳遞一個短代碼字符串:
do_shortcode( '[ihc-hide-content ihc_mb_who="5,7"][my_shortcode][/ihc-hide-content]' );
如果這不起作用( my_shortcode
,它應該) - 您可以嘗試將my_shortcode
的輸出生成到輸出緩沖區中,如下所示:
// 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]' );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.