php 如何在模板中调用 WordPress 短代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19293420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I call a WordPress shortcode within a template?
提问by LeRoy
There's a plugin for the Contact us form.
联系我们表单有一个插件。
To activate the form, all you have to do is to place [CONTACT-US-FORM]
in the page...
要激活表单,您只需[CONTACT-US-FORM]
在页面中放置...
My page is calling a page template. Is it possible to add the [CONTACT-US-FORM] shortcode in the PHP template?
我的页面正在调用页面模板。是否可以在 PHP 模板中添加 [CONTACT-US-FORM] 短代码?
I tried it and it did not work.
我试过了,但没有用。
The WordPress pageworked, but not the method I want.
在WordPress的页面的工作,但不是我想要的方法。
[CONTACT-US-FORM]
PHP Contact Us templateI want to try something like this, but it did not work.
PHP Contact Us 模板我想尝试这样的事情,但没有奏效。
<?php
/*
Template Name: [contact us]
*/
get_header(); ?>
[CONTACT-US-FORM]
<?php get_footer(); ?>
回答by codepixlabs
echo do_shortcode('[CONTACT-US-FORM]');
Use this in your template.
在您的模板中使用它。
Look here for more: Do Shortcode
在这里查看更多信息:做短代码
回答by user2682025
Try this:
尝试这个:
<?php
/*
Template Name: [contact us]
*/
get_header();
echo do_shortcode('[CONTACT-US-FORM]');
?>
回答by Junaid
Make sure to enablethe use of shortcodes in text widgets.
确保在文本小部件中启用短代码的使用。
To do so, add this in your functions.phpfile:
为此,请在您的functions.php文件中添加以下内容:
add_filter( 'widget_text', 'do_shortcode' );
And then you can use it in any PHP file:
然后你可以在任何 PHP 文件中使用它:
<?php echo do_shortcode('[YOUR-SHORTCODE-NAME/TAG]'); ?>
Check the documentationfor more.
查看文档了解更多信息。