2017-08-01 100 views
0

我在wordpress面板中輸入shortcode in post。我想要顯示我在single.php輸入的自定義HTML代碼,例如,當這個簡碼被激活時。我試過這段代碼,但它不起作用。Wordpress短代碼顯示

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

你可以添加完整的代碼,你已經爲secondfloor創建shortcode。 – sunilsingh

回答

0

您需要使用此代碼:

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]');