Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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
You can’t perform that action at this time.