Search code examples
phpwordpressshortcode

How to create a shortcode for custom page template?


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, 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?


Solution

  • 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' );