• Resolved NatESkiN

    (@nateskin)


    Hello everyone,

    I’m working on a theme based on Twentyfourteen. I’m working on a hack to show a different background when a “featured post” in action “wp_head” declared my file functions.php.

    I’ve tried a thousand different options. Passing a variable to the function that called the “wp_head” (which passed the variable twice) or adding a filter, but it still fails. This I have tried in the “content-featured-post.php” file.

    I’m a little desperate and I do not get a solution. Could you give me some idea?

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I believe that wp_add_inline_style () function; solves your problem. With it you can set a css style dynamically, eg if you want the background of the main div is white on the home page and red on the inside pages so you do something in HTML;

    <div class="mycolor">
    / / Here goes the rest of your HTML
    </ div>

    And in functions.php you would use such a code:

    function my_styles_method() {
    	wp_enqueue_style(
    		'custom-style',
    		get_template_directory_uri() . '/css/custom_script.css'
    	);
            if( is_home() )
            	$color = '#FFF';
           	else
           		$color = '#FF0000';
            $custom_css = "
                    .mycolor{
                            background: {$color};
                    }";
            wp_add_inline_style( 'custom-style', $custom_css );
    }
    add_action( 'wp_enqueue_scripts', 'my_styles_method' );

    I believe that with this example it is possible to start working, for more information see the CODEX: http://codex.wordpress.org/Function_Reference/wp_add_inline_style the code above hi done based on his example.

    Thread Starter NatESkiN

    (@nateskin)

    Thanks Leo for your answer!
    Hope it works!

    If you do everything right it will work, if you have problems around here!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Passing a variable to a function that calls "wp_head"’ is closed to new replies.