简体   繁体   中英

How can I call a WordPress shortcode within a template?

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(); ?>
echo do_shortcode('[CONTACT-US-FORM]');

Use this in your template.

Look here for more: Do Shortcode

Try this:

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

*/
get_header();
echo do_shortcode('[CONTACT-US-FORM]'); 
?>

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

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

Check the documentation for more.

// Use shortcode in a PHP file (outside the post editor).

echo do_shortcode( '' );

// Use shortcodes in form like Landing Page Template.

echo do_shortcode( '[contact-form-7 id="91" title="quote"]' );

//Same Way

echo do_shortcode('[CONTACT-US-FORM]');

Please just go through the reference link [Link]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM