Created
April 26, 2019 21:29
-
-
Save damiencarbery/43cf6107dc2e5d9ec5261839c1e70f77 to your computer and use it in GitHub Desktop.
How to Add Page Slug in Body Class of your WordPress Themes - https://www.wpbeginner.com/wp-themes/how-to-add-page-slug-in-body-class-of-your-wordpress-themes/
This file contains 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: Slug to Body Class | |
Version: 0.1 | |
Plugin URI: http://www.wpbeginner.com/wp-themes/how-to-add-page-slug-in-body-class-of-your-wordpress-themes/ | |
Description: Add Page/Post Slug to Body Class | |
Author: Syed Balkhi | |
Author URI: https://plus.google.com/101623299936375408403/ | |
*/ | |
// From: http://www.wpbeginner.com/wp-themes/how-to-add-page-slug-in-body-class-of-your-wordpress-themes/ | |
add_filter( 'body_class', 'add_slug_body_class' ); | |
function add_slug_body_class($classes) { | |
global $post; | |
if ( isset( $post ) ) { | |
$classes[] = $post->post_type . '-' . $post->post_name; | |
} | |
return $classes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment