Wordpress短代码显示

问题描述:

我在wordpress面板中输入shortcode in post。我想要显示我在single.php输入的自定义HTML代码,例如,当这个简码被激活时。我试过这段代码,但它不起作用。Wordpress短代码显示

<?php 
    if (shortcode_exists('secondfloor')) { 
     echo '<h2>Mytag</h2>'; 
} ?> 
+0

你可以添加完整的代码,你已经为secondfloor创建shortcode。 – sunilsingh

您需要使用此代码:

if (!shortcode_exists('hello_world')) { 
    add_shortcode('hello_world', 'hello_world'); 
    function hello_world() { 
     $html = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 
     return $html; 
    } 
} 

使用编辑器:

[hello_world] 

在PHP文件用途:

echo do_shortcode('[hello_world]');