Skip to content

Instantly share code, notes, and snippets.

@yratof
Last active November 21, 2016 10:16
Show Gist options
  • Save yratof/dfe019a54d7a90146ab976e717f0393d to your computer and use it in GitHub Desktop.
Save yratof/dfe019a54d7a90146ab976e717f0393d to your computer and use it in GitHub Desktop.
Craft Header Reshuffle
<?php
/**
* How to rearrange your header when using Craft
*/
class craft_headers {
// Load classes before
static function setup(){
add_action( 'init', __CLASS__ . '::cleanup', 10 );
add_action( 'init', __CLASS__ . '::reshuffle', 20 );
}
// Remove the header elements one by one
static function cleanup() {
// Remove all elements from the header
remove_action( 'drivkraft_header_top_left', 'drivkraft_header::header_top_left', 10 ); // Remove USPs
remove_action( 'drivkraft_header_top_center', 'drivkraft_header::header_top_center', 10 ); // Remove logo
remove_action( 'drivkraft_header_top_right', 'drivkraft_header::header_top_right', 10 ); // Remove Account links
remove_action( 'drivkraft_header_bottom_left', 'drivkraft_header::header_bottom_left', 10 ); // Remove search
remove_action( 'drivkraft_header_bottom_center', 'drivkraft_header::header_bottom_center', 10 ); // Remove navigation
remove_action( 'drivkraft_header_bottom_right', 'drivkraft_header::header_bottom_right', 10 ); // Remove cart
// Clean up the classes back to the defaults
add_filter( 'craft_header_top_left_classes', function(){ return 'header--top--left'; }, 10, 1 );
add_filter( 'craft_header_top_center_classes', function(){ return 'header--top--center'; }, 10, 1 );
add_filter( 'craft_header_top_right_classes', function(){ return 'header--top--right'; }, 10, 1 );
add_filter( 'craft_header_bottom_left_classes', function(){ return 'header--bottom--left'; }, 10, 1 );
add_filter( 'craft_header_bottom_right_classes', function(){ return 'header--bottom--right'; }, 10, 1 );
}
// Put everything back in a new place
static function reshuffle(){
// New order of navigation elements
add_action( 'drivkraft_header_bottom_left', 'drivkraft_header::header_top_center' ); // Place logo at the bottom left
add_action( 'drivkraft_header_bottom_right', __CLASS__ . '::child_header_bottom_right' ); // Move search to right
add_filter( 'craft_header_bottom_left_classes', __CLASS__ . '::remove_header_search_class', 10, 1 );
add_filter( 'craft_header_bottom_right_classes', __CLASS__ . '::remove_header_cart_class', 10, 1 );
// After the header, you can assign addition elements. If you want a full width
// navigation, this is the place for that:
add_action( 'drivcraft_after_header', 'drivkraft_header::header_bottom_center', 10 );
}
}
craft_headers::setup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment