Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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(); ?> 
like image 615
LeRoy Avatar asked Oct 10 '13 10:10

LeRoy


People also ask

How do I add a shortcode to a theme?

Where to Add Your Custom Shortcode Scripts? You can add your custom shortcode scripts to the theme's functions. php file or include them in a plugin. If you're adding it to a theme file, you can run the add_shortcode() function as is.

How do you call short codes?

Short codes are special phone numbers that give you quick access to information, services, and call features. To use a short code: Enter the number and touch the phone icon below the keypad to make the call.


2 Answers

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

Use this in your template.

Look here for more: Do Shortcode

like image 136
Prince Singh Avatar answered Oct 14 '22 12:10

Prince Singh


Try this:

<?php  /* Template Name: [contact us]  */ get_header(); echo do_shortcode('[CONTACT-US-FORM]');  ?> 
like image 20
user2682025 Avatar answered Oct 14 '22 12:10

user2682025