here:
add_filter('body_class','body_class_slugs');
function body_class_slugs($classes) {
global $posts,$post;
if(is_single() || is_page()){ //only on a single post or page
if (isset($posts)){
$classes[] = $post[0]->post_name; //posts is an array of posts so we use the first one by calling [0]
}
elseif (isset($post)){
$classes[] = $post->post_name;
}
}
return $classes;
}
Related Posts:
- Redirect to another page using contact form 7? [closed]
- remove empty paragraphs from the_content?
- How to get a taxonomy term name by the slug?
- Redeclare/Change Slug of a Plugin’s Custom Post Type
- Issues with title-tag and document_title_parts
- Is there a maximum slug length?
- Remove Actions/Filters added via Anonymous Functions
- How to check if a slug exists?
- Can I use a number for a post/page slug?
- How to make a image-size selected by default in Media upload – WP v3.5
- Set JPEG compression for specific custom image sizes
- Force post slug to be auto generated from title on save
- Sort search results by post type
- Apply class to every paragraph that holds image?
- Removing Metabox for “Slug” without removing functionality
- Remove “Insert from URL” link in Media upload – WP 3.5
- Define custom Page Template without its own .php file
- static variable loop not working in WordPress
- Add class to menu items of one specific menu (nav_menu_css_class)
- Change admin bar to default:off
- How to influence the information displayed on widget inside wp-admin
- How to rewrite slug of custom post type archive page
- adding a filter to a shortcode?
- Removing default image size list in Media Box
- Set media upload attachment link to none and hide it in WP v3.5
- How to get full slug, including all parent pages
- How to publish a post with empty title and empty content?
- How to restrict actions and filters “properly” by conditions
- Filter the query ONLY for the search results page
- opening links in new tab using – add_filter( ‘the_content’, ‘make_clickable’);
- ajax category filter
- Using add_filter() in Widgets
- Customize WordPress Media Manager – Media Window
- Remove Slug from Custom Post Type
- Don’t replace “|” with Empty String (“”) when generating slugs from title
- How to reduce original image quality on upload?
- function triggered by “manage_users_custom_column” filter not working
- Is it possible to use a forgot password url filter?
- Change the footer text on the login page
- syntax for remove_filter in parent theme with class
- Add body class of category parent
- Add warning to edit slug/permalink button on editor screen.
- add_filter to post-gallery and remove all ‘s?
- which is the function that removes accented vowels?
- Slugs as breadcrumbs for Pages
- How to overwrite youtube embed?
- Determine which theme location a wp_get_nav_menu_items is for
- Rewriting search and pagination base
- Wrap gutenberg block ‘div’ in other elements/extra HTML
- Check if page parent has certain template
- Convert hyphen to underscore in permalinks
- How to prevent duplicate slugs for wp_insert_post?
- Override parent theme function that is not hooked or in the functions.php file
- Remove Page Title from Static Frontpage
- Programmatically Add Font-Awesome Icons to Category Widget
- Get password when user registers and save it sha1 into database
- Change comments form title on a page by page basis
- How to remove certain words from url slug
- Remove bulk actions based on user role or capabilities
- How to generate slugs?
- Removing user contact methods works from functions.php but not from a plugin
- Remove class that has been added by parent theme
- Default or Preset Content for Custom Post Types
- Dynamically Override Fancy Title
- How to get any tag ID
- {Check Theme Plugin} text domain does not match the theme’s slug
- Alter post slug by a filter that is fired just after a post is created
- Override a class function to include a custom template
- How to override filter in child theme?
- Possible to create a new post and have the Title and Slug automatically use the post’s ID?
- Removing title from page
- Hide some items from Screen options in dashboard for products
- How to change a certain text or term of WordPress into a custom into the whole site?
- Display page over category archive
- Convert post name into post ID
- WP appending -2 to the end of my slug. Where are the originals stored so I can delete them?
- Adding body class when post contains a specific shortcode
- How do I know what variables are passed in a filter/action and what their meaning is?
- Yoast SEO breadcrumbs: how to create a filter that uses the url slug for breadcrumb titles
- Why do filters/actions require an argument count?
- Function to list all post slugs for every post in my WP database?
- Replace Archive Widget Link Text
- Does add_filter work outside functions.php
- Exclude Empty Child Categories in Menu
- How to make unique add_filter to the_content of specific page template files – so each template gets its own addition
- Get page slug and assign a variable within functions.php
- Best way to programatically add “rel” attributes to page and post images
- How I Can Use The Get Value as A Slug
- How to get Custom Post ID by adding filter to child theme’s function
- add_filter priority problem
- Limit filter upgrader_post_install to a single plugin
- Set taxonomy slug as taxonomy title
- custom slug always ends in “-2”
- Custom Taxonomy breaking pages permalinks
- How to update feed only 2-3 times a week (for Feedburner email)?
- Manipulate Output of wp_list_something: select menu instead of li’s
- Clean-up script tags
- How to use IF Statement in WordPress?
- Gravity Forms field entries into wp_query loop [closed]
- Show all wp_get_post_terms slugs