Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Created April 26, 2019 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damiencarbery/43cf6107dc2e5d9ec5261839c1e70f77 to your computer and use it in GitHub Desktop.
Save damiencarbery/43cf6107dc2e5d9ec5261839c1e70f77 to your computer and use it in GitHub Desktop.
<?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