Apologies for the lackluster title. I am curious if there's something similar in Wordpress as Nunjucks call or block.

Essentially, I am curious if it is possible to create a template part and inject html markup somewhere within that template part.

Currently I am accomplishing this by passing a variable, that contains my markup, to the template part. Example below:


<?php $markup = get_query_var("markup"); ?>
<div class="container">
    <?php echo $markup ?>


    $markup = "
    set_query_var("markup", $markup);

However, I would prefer a method that would look similar to this (obviously I using fictional method names here):


<?php start_template_part("partials/template-part"); ?>
<?php end_template_part("partials/template-part"); ?>

Is there something similar in Wordpress that would allow me to accomplish the second method?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.