简体   繁体   中英

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?

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

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