Skip to content

Instantly share code, notes, and snippets.

@utkrishta
Created April 8, 2022 01:49
Show Gist options
  • Save utkrishta/4b51f2fd4c84979f1bc0ec0adf0c9833 to your computer and use it in GitHub Desktop.
Save utkrishta/4b51f2fd4c84979f1bc0ec0adf0c9833 to your computer and use it in GitHub Desktop.
Create a custom shortcode that calls and display content from another file/tempalate part
<?php
/*
* Create a custom shortcode that calls and display content from another file/tempalate part
*
* We have a file called custom-form.php inside inc folder which contains our custom form codes
*
*/
function custom_form( $atts, $content, $shortcode_tag ){
ob_start();
get_template_part('inc/custom-form');
$form = ob_get_contents();
ob_end_clean();
return $form;
}
add_shortcode( 'custom-form', 'custom_form' );
/*
* Now we can just use [custom-form] shortcode to call the custom form
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment