1

I have a custom page template and I want it to display on specific pages. The only way I know to do this is to create a shortcode for this custom page template, so that I can use the custom page template by using shortcode. But I don't know how doing this.

I saw some article about this, but I forgot the website link.

How to create a shortcode for custom page template?

7
  • What you are asking doesn't really make sense. Can you please provide more detail?
    – s_ha_dum
    Commented Oct 20, 2015 at 3:46
  • @s_ha_dum, what i need is, to create a shortcode for custom page tempate Commented Oct 20, 2015 at 4:05
  • Yes. Repeating the same thing you wrote before increases clarity a great deal.
    – s_ha_dum
    Commented Oct 20, 2015 at 4:49
  • I think you need a shortcode to call a template part to include that part inside a page content, is that right? Commented Oct 20, 2015 at 5:24
  • yes. my snippet below is correct? Commented Oct 20, 2015 at 5:28

3 Answers 3

8

I solved now, by adding this snippet in functions.php

function my_form_shortcode() {
   ob_start();
   get_template_part('my_form_template');
   return ob_get_clean();   
} 
add_shortcode( 'my_form_shortcode', 'my_form_shortcode' );
2
  • hats off.. a genius hack wordpress..
    – Naresh
    Commented Sep 5, 2018 at 8:37
  • @user3818821, what is the my_form_template? is this template ID? Commented Jan 21, 2022 at 9:17
1

I solved using below method.

Using Plugin (Shortcodes Ultimate) we can create or make shortcode for wordpress custom page template.

  1. create your custom page template without including header and footer.
  2. Install the plugin(find link below) into wordpress site.
  3. Activate it.
  4. Go to plugin Shortcodes Ultimate › Available shortcodes.
  5. You can find the variety of filter options in that click Other will find Template open that.
  6. In shortcode section add the name of your custom template([su_template name="name-of-your-template.php"]) with or without php extentions.
  7. Use template file name (with optional .php extension). If you need to use templates from theme sub-folder, use relative path. Example values: page, page.php, includes/page.php
  8. Now copy the whole shortcode and paste it into the page or post you want.

Plugin download link

Shortcodes Ultimate

1

I find this one is the easiest way:

<?php echo do_shortcode("[shortcode]"); ?>
1
  • 1
    This question is about how to add a new shortcode, not use one.
    – mozboz
    Commented Jul 31, 2020 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.