-
-
Save tommcfarlin/ac53e281c2a30579a1d3 to your computer and use it in GitHub Desktop.
[WordPress] A simple example for how to include a template part from a plugin using `the_content` hook.
This file contains 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 | |
add_action( 'the_content', 'acme_add_template_part' ); | |
function acme_add_template_part( $content ) { | |
ob_start(); | |
require plugin_dir_path( dirname( __FILE__ ) ) . '/includes/templates/acme-my-template.php'; | |
$template = ob_get_contents(); | |
$content .= $template; | |
ob_end_clean(); | |
return $content; | |
} |
This file contains 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 | |
/** | |
* Template Name: Acme Template Part | |
* | |
* @since 1.0.0 | |
*/ | |
?> | |
<form action="#" method="post"> | |
<p> | |
<label for="acme-firstname">First Name <span class="acme-required">*</span></label> | |
<input type="text" id="acme-firstname" name="acme-firstname"> | |
</p> | |
<p> | |
<input type="submit" value="Submit"> | |
</p> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment