Support » Themes and Templates » global variables in theme's function.php

  • Hi,
    I am writing a customer theme, and want to use a global variable in the function.php.
    It looks like the global variable is loosing it value which is set in a filter function.

    How can I achieve that the value, which is set in the filter function is available in the function.php?

    Here is the code of my function.php showing the issue I have.

    //register menue locations
    function register_my_menus() {
        global $helperClass;
                array('top-menu' => __('Top Menu'),
                    'left-menu' => __('Left Menu'))
    add_action('init', 'register_my_menus');
    // add hook
    add_filter('wp_nav_menu_objects', 'my_wp_nav_menu_objects_sub_menu', 10, 2);
    // filter_hook function to react on sub_menu flag
    function my_wp_nav_menu_objects_sub_menu($sorted_menu_items, $args) {
        global $myGlobalVar;
        $myGlobalVar = array("this is a global var", "This as well");
        return $sorted_menu_items;

    thanks to all of you for helping me here.

  • The topic ‘global variables in theme's function.php’ is closed to new replies.