Created
April 8, 2022 01:49
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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