Skip to content

Instantly share code, notes, and snippets.

@andornagy
Last active December 31, 2015 01:19
Show Gist options
  • Save andornagy/7913201 to your computer and use it in GitHub Desktop.
Save andornagy/7913201 to your computer and use it in GitHub Desktop.
<?php
function get_my_header() {
// if is home, which is the front page
if(is_home()) {
// then get the header-home.php
get_header('home');
// else get the normal header.php
} else {
get_header();
}
}
<?php
function get_my_header() {
if( !is_home() ) {
global $post;
// get category by ID
$category = get_the_category($post->ID);
// first category slug
$catslug = $category[0]->slug;
// is there is a category slug call the header-$catslug.pgp
if (isset($catslug)) {
get_header($catslug);
} else {
// else call normal header.php
get_header();
}// ends !is_home()
// else call normal header
} else {
get_header();
}// ends isset()
} // ends get_myheader function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment