Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created June 18, 2014 11:52
Show Gist options
  • Save tommcfarlin/ac53e281c2a30579a1d3 to your computer and use it in GitHub Desktop.
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.
<?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;
}
<?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