Each template has a pre-defined set of variables passed to it by core. You can also pass your own custom params (variables or functions) to templates by using the template-args filter:

Pass additional data to all templates

For example to pass a “user_is_logged_in” variable to all templates in your theme:

Then you can test if a user is logged in in your templates using the “user_is_logged_in” variable:

Pass additional data to a chosen template

To pass custom data stored in local storage (under the “my-data” key, using the PersistentStorage module) to the “my-custom-template.html” template:

Then to use our custom data in “my-custom-template.html” template:

Pass functions to templates

To pass a date formatting function to single, page and archive templates:

Then use our format_date function in templates:

To Know More

More on “template-args” filter here.

General notions about templates can be found in the “Template Files” section of the doc.

Also see the tutorial about customizing templates.

Published by Mathieu on January 5, 2017

Freelance Senior Web Developer, WordPress since 2009, JS/Backbone since 2012, Custom Back-End devs, WebApps and Plugins for clients and the community.

Leave a Reply

Your email address will not be published.

Having questions?

FAQ | Tutorials | Documentation


Contact Us