How to use PHP global variables in header.php or function.php

In WordPress, you can use common variables across files by using PHP global variables inheader.php orfunction.php.

Specifically, the code is as follows

global $variable;. 

This makes $variable accessible within the subsequent scope. This is very useful when a variable needs to be shared among multiple functions or files.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top