2

I am calling the header on a custom template page with get_header(); but the header loads without the style.css breaking the site. I noticed that if I place the header on top of some code, the style sheet loads just fine, for example:

<?php
/*
    Template Name: Sample Template
*/

get_header();

//some code here

I need to load the header below some code since I am using a cookie and as of my knowledge, cookies should be generated before any HTML.

1 Answer 1

5

Don't place any code above get_header(). Instead, use actions to "hook" and do some work there.

For example, you could use get_header action like this:

// in functions.php :

add_action( 'get_header', 'set_my_cookies' );
function set_my_cookies() {
    // ... set those cookies
}

See http://codex.wordpress.org/Plugin_API/Action_Reference/get_header

And more about actions: http://codex.wordpress.org/Plugin_API

It might take a bit to get one's head around actions (and filters) at first, but those are crucial concepts in WordPress, so it's definitely worth it!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.