Skip to main content
added 46 characters in body
Source Link
kaiser
  • 50.8k
  • 27
  • 150
  • 244

Based upon @toscho snippet, here's a real life example. Assuming that you don't need to access a var directly from inside the template file.

function wpse_69365_var_storage()
{
    static $internal;

    if ( 'wp_head' === current_filter() )
    {
        if ( /* Condition is met */ )
            return $internal = 4; // Set to what you need.

        return 'default_value';
    }

    return print $internal;
}
// Call in header.php:
add_action( 'wp_head', 'wpse_69365_var_storage' );
// Call in footer.php:
add_action( 'wp_footer', 'wpse_69365_var_storage' );

Based upon @toscho snippet, here's a real life example. Assuming that you don't need to access a var directly from inside the template file.

function wpse_69365_var_storage()
{
    static $internal;

    if ( 'wp_head' === current_filter() )
    {
        if ( /* Condition is met */ )
            $internal = 4; // Set to what you need.
    }

    return print $internal;
}
// Call in header.php:
add_action( 'wp_head', 'wpse_69365_var_storage' );
// Call in footer.php:
add_action( 'wp_footer', 'wpse_69365_var_storage' );

Based upon @toscho snippet, here's a real life example. Assuming that you don't need to access a var directly from inside the template file.

function wpse_69365_var_storage()
{
    static $internal;

    if ( 'wp_head' === current_filter() )
    {
        if ( /* Condition is met */ )
            return $internal = 4; // Set to what you need.

        return 'default_value';
    }

    return print $internal;
}
// Call in header.php:
add_action( 'wp_head', 'wpse_69365_var_storage' );
// Call in footer.php:
add_action( 'wp_footer', 'wpse_69365_var_storage' );
Source Link
kaiser
  • 50.8k
  • 27
  • 150
  • 244

Based upon @toscho snippet, here's a real life example. Assuming that you don't need to access a var directly from inside the template file.

function wpse_69365_var_storage()
{
    static $internal;

    if ( 'wp_head' === current_filter() )
    {
        if ( /* Condition is met */ )
            $internal = 4; // Set to what you need.
    }

    return print $internal;
}
// Call in header.php:
add_action( 'wp_head', 'wpse_69365_var_storage' );
// Call in footer.php:
add_action( 'wp_footer', 'wpse_69365_var_storage' );