Skip to content

Instantly share code, notes, and snippets.

@bradpotter
Last active August 29, 2015 14:15
Show Gist options
  • Save bradpotter/c655bc2f295b7515d7bc to your computer and use it in GitHub Desktop.
Save bradpotter/c655bc2f295b7515d7bc to your computer and use it in GitHub Desktop.
Change body class via a custom field value in order to change post or page layout
<body <?php
$layout = get_post_meta($post->ID, 'layout', true);
if ( is_singular() && $layout == 'sidebar-content' ) {
body_class( 'sidebar-content' );
}
elseif ( is_singular() && $layout == 'full-width-content' ) {
body_class( 'full-width-content' );
unregister_sidebar( 'sidebar-primary' );
}
else {
body_class( 'content-sidebar' );
}
?> itemscope="itemscope" itemtype="http://schema.org/WebPage">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment