0

So let's say that I have a navbar template with the following content:

// template_parts / navbar.php

<nav class="navbar navbar-expand-lg dark bg-transparent fixed-top" id="mainNav">
  <div class="container">
    <a class="navbar-brand" href="./">
     This is the company name
    </a>
  </div>
</nav>

Is there a way to pass a variable to the template in order to change, in this case, the company's name when calling the template?

Something like get_template_part("template_parts/navbar","Microsoft");

I know the above syntax works for another purpose, I'm just trying to illustrate what I want to achieve.

Is there a way to do this? Thanks beforehand!

1

1 Answer 1

0

You can include the template like this include(locate_template('template-part.php'));. to pass the variable or used the outer variable/ dynamic values in the template.

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.