PHP variables in the header

I have a minor issue with my site, for most of my sites images I have it set up as variables in functions.php so I can change them easily… however I cant seem to access those while im working on the header… I have to define the variables in the header itself for that file to see the variables.

Id imagine what that means is header.php is ran before functions.php, assuming thats why this is happening is there a way to change that so functions.php is ran before any of the pages?

Thanks

  • LCDist
    • The Incredible Code Injector
    define( 'THEME_URI', get_template_directory_uri() );
    define( 'THEME_DIR', get_template_directory() );
    define( 'THEME_IMG', THEME_URI . '/img' );
    $lcno = '<img src="' . THEME_IMG. '/no.png" alt="No" title="No" />';
    $lcyes = '<img src="' . THEME_IMG. '/yes.png" alt="Yes" title="Yes" />';

    so how would you do somthing like that… to me it looks right lookin at that site… but Im still new and making lots of mistakes…it works everywhere but the header.php

  • Mason
    • DEV MAN’s Sidekick

    Hiya LCD,

    Try this in your functions.php file:

    define('LCNO', '/imag/no.png');
    define('LCYES', '/img/yes.png');

    Then anytime you want to pull up one of the images, you’d add the following in your theme:

    <img src="<?php echo get_stylesheet_directory_uri(); ?><?php echo LCYES ?>" />

    The above example will display the YES image. It will also work for sites using child themes (since we’re using get_stylesheet_directory_uri)

    Hope this helps!

    *Edit* After talking to one of our designers, you’ll probably want to use template_directory_uri() as it is future proof for WP 3.3.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.