How to define a global variable in WordPress

Posted on: March 13th, 2024
By: Tadeo Martinez

You can set this in your functions.php.

global $options;
$options = get_option( 'my_framework' ); // unique id of the framework

global $logoImg;
$logoImg = $options['opt-media-1']['id'];

This particular case is using the Codestar framework for global settings but the main point is that you define a global variable as global and then set its value.

Have any questions or comments? Write them below!


Leave a Reply

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