插件的简码不起作用



你好,我试过如下

$my_postid = 12;//This is page id 
$content_post = get_post($my_postid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;

我在id为12的页面中编写了短代码。这行不通。请帮助! !div !

可以使用get_shortcode_regex函数检查帖子内容,隔离短码。将my_shortcode替换为您试图获得的短代码的实际标识符:

$content_post = get_post( 12 );
$content = apply_filters( 'the_content', $content_post->post_content );
$pattern = get_shortcode_regex();
preg_match( '/' . $pattern . '/s', $content, $matches );
if ( is_array( $matches ) && $matches[2] == 'my_shortcode' ) {
    $shortcode = $matches[0];
    echo do_shortcode( $shortcode );
}

最新更新