【问题标题】:How can I call a WordPress shortcode within a template?如何在模板中调用 WordPress 短代码?
【发布时间】:2013-10-18 01:47:30
【问题描述】:

Contact us form 有一个插件。

要激活表单,您只需在页面中输入[CONTACT-US-FORM]...

我的页面正在调用页面模板。 是否可以在 PHP 模板中添加 [CONTACT-US-FORM] 短代码?

我试过了,没用。

WordPress 页面有效,但不是我想要的方法。

[CONTACT-US-FORM]

PHP 联系我们模板我想尝试这样的方法,但没有成功。

<?php
/*
Template Name: [contact us]

*/
get_header(); ?>
[CONTACT-US-FORM]
<?php get_footer(); ?>

【问题讨论】:

    标签: php css wordpress plugins


    【解决方案1】:
    echo do_shortcode('[CONTACT-US-FORM]');
    

    在您的模板中使用它。

    查看更多信息:Do Shortcode

    【讨论】:

    • 谢谢工作
    【解决方案2】:

    试试这个:

    <?php 
    /*
    Template Name: [contact us]
    
    */
    get_header();
    echo do_shortcode('[CONTACT-US-FORM]'); 
    ?>
    

    【讨论】:

    • 解释一下。例如,要点/想法是什么?
    【解决方案3】:

    确保在文本小部件中启用短代码的使用

    // To enable the use, add this in your *functions.php* file:
    add_filter( 'widget_text', 'do_shortcode' );
    
    // and then you can use it in any PHP file:  
    <?php echo do_shortcode('[YOUR-SHORTCODE-NAME/TAG]'); ?>
    

    查看the documentation了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-26
      • 2016-04-06
      • 2019-09-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多