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 badges1 Answer
Reset to default 2The 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' );