How can I call a WordPress shortcode within a temp

2020-02-17 05:56发布

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...

My page is calling a page template. Is it possible to add the [CONTACT-US-FORM] shortcode in the PHP template?

I tried it and it did not work.

The WordPress page worked, but not the method I want.

[CONTACT-US-FORM]

PHP Contact Us template I want to try something like this, but it did not work.

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

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

3条回答
兄弟一词,经得起流年.
2楼-- · 2020-02-17 06:11
echo do_shortcode('[CONTACT-US-FORM]');

Use this in your template.

Look here for more: Do Shortcode

查看更多
Animai°情兽
3楼-- · 2020-02-17 06:11

Make sure to enable the use of shortcodes in text widgets.

To do so, 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]'); ?>

Check the documentation for more.

查看更多
SAY GOODBYE
4楼-- · 2020-02-17 06:22

Try this:

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

*/
get_header();
echo do_shortcode('[CONTACT-US-FORM]'); 
?>
查看更多
登录 后发表回答