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?

  • What you are asking doesn't really make sense. Can you please provide more detail? – s_ha_dum Oct 20 '15 at 3:46
  • @s_ha_dum, what i need is, to create a shortcode for custom page tempate – user3818821 Oct 20 '15 at 4:05
  • Yes. Repeating the same thing you wrote before increases clarity a great deal. – s_ha_dum Oct 20 '15 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? – Fernando Baltazar Oct 20 '15 at 5:24
  • yes. my snippet below is correct? – user3818821 Oct 20 '15 at 5:28
4

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' );
  • hats off.. a genius hack wordpress.. – Puzzled Boy Sep 5 '18 at 8:37
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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