Last active
December 4, 2018 18:04
-
-
Save alanef/3501bc4bae58d690818e193a79c9179d to your computer and use it in GitHub Desktop.
body id function for genesis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: Add IDs to body tag for Genesis | |
| * Plugin URI: https://fullworks.net/products/custom-plugin-development/ | |
| * Description: Add IDs to body tag | |
| * Version: 1.0.0 | |
| * Author: Alan Fuller | |
| * Author URI: https://fullworks.net/products/custom-plugin-development/ | |
| * License: GPL-2.0+ | |
| */ | |
| // If this file is called directly, abort. | |
| if ( ! defined( 'WPINC' ) ) { | |
| die; | |
| } | |
| // add the post name as a class to single | |
| add_filter( 'body_class', function ( $classes ) { | |
| if ( is_single() ) { | |
| global $post; | |
| $classes[] = $post->post_name; | |
| } | |
| } ); | |
| // add id to body depending on type | |
| add_filter( 'genesis_attr_body', function ( $attributes ) { | |
| if ( is_home() ) { | |
| $attributes['id'] = 'home'; | |
| } elseif ( is_single() ) { | |
| $attributes['id'] = 'single'; | |
| } elseif ( is_search() ) { | |
| $attributes['id'] = 'search'; | |
| } elseif ( is_archive() ) { | |
| $attributes['id'] = 'archive'; | |
| } | |
| return $attributes; | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment