theme development - How do I create a custom partialtemplate?

admin2025-06-05  12

I have created an sign up form and placed it in my header:

<div>
    <h5 class="myapp-sign-up-text">Sign up for updates</h5>
    <form class="myapp-email-form">
        <input type="text" name="email" placeholder="Your email address" class="myapp-subscription-input" />
        <input type="submit" value="Subscribe" class="myapp-subscription-submit" />
    </form>
</div>

I would like to use the same code for my footer. Is there a DRY way of putting this into a partial and loading it using a PHP function?

I have created an sign up form and placed it in my header:

<div>
    <h5 class="myapp-sign-up-text">Sign up for updates</h5>
    <form class="myapp-email-form">
        <input type="text" name="email" placeholder="Your email address" class="myapp-subscription-input" />
        <input type="submit" value="Subscribe" class="myapp-subscription-submit" />
    </form>
</div>

I would like to use the same code for my footer. Is there a DRY way of putting this into a partial and loading it using a PHP function?

Share Improve this question edited Dec 5, 2018 at 21:56 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Dec 5, 2018 at 21:33 bigpotatobigpotato 3352 gold badges6 silver badges17 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

The thing you're searching for is get_template_part function.

So let's say you put your form in file called part-form-signup.php. Then you can easily include that partial template anywhere using:

get_template_part( 'part-form-signup' );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749125267a316578.html

最新回复(0)