FYI before you mark it as duplicate: I found some similar questions, but they are from like 4 years ago and WP is constantly evolving.

For repetitive chunks like this I used posts to convert an HTML theme into WP:

<ul class="slides">
       <div class="testimonails-content">
         <p>Lorem ipsum blah blah </p>
       <h6>Title <a href="#">Customer</a></h6>

What can I use for small unique pieces of text like this:

<div class="heading-section">
   <h2>A small heading</h2>
      <img src="" alt="" >

Is using posts ok, or there is a more or less standard way for it?

  • 3
    Chances are the old posts are still accurate in principle.
    – s_ha_dum
    Jun 29, 2015 at 22:02
  • why don't you try get_template_part
    – Karun
    Jun 30, 2015 at 2:01

1 Answer 1


I'd say there are roughly two approaches to this:

1 Use get_template_part(). This is the normal way of inserting pieces of code into a template. However, you cannot pass arguments to this function. So if you want to repeat ten pieces of code with small variations, you cannot tell get_template_part what the variations are. It is possible to get around this: Passing a variable to get_template_part

2 Use an action hook. This will allow you to pass a variable to a function that generates a piece of html. In your theme you would have do_action('my_hook',$args), while in your functions file you would define add_action ('my_hook','my_hook_action');. This may be more practical, but slightly less standard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.