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]
- Removing Metabox for “Slug” without removing functionality
- Remove “Insert from URL” link in Media upload – WP 3.5
- Removing default image size list in Media Box
- How to restrict actions and filters “properly” by conditions
- ajax category filter
- which is the function that removes accented vowels?
- Slugs as breadcrumbs for Pages
- How to get any tag ID
- Alter post slug by a filter that is fired just after a post is created
- WP appending -2 to the end of my slug. Where are the originals stored so I can delete them?
- Yoast SEO breadcrumbs: how to create a filter that uses the url slug for breadcrumb titles
- Exclude Empty Child Categories in Menu
- Get page slug and assign a variable within functions.php
- How I Can Use The Get Value as A Slug
- Custom Taxonomy breaking pages permalinks
- Remove function or filter
- Get posts with at least one category in common with current post?
- Sanitize slug title
- How to add numeric slug for child page in WordPress 5.9?
- Filter categories of posts with checkboxes
- Adding multiple taxonomy filters to functions.php
- WooCommerce product search titles only
- Make wp_list_pages print slugs instead of titles
- Stripping unicode characters out of slug
- Remove slugs of old and unused custom post type
- How to append to title via functions.php for auto-posting plugin [duplicate]
- Only let plugin add actions to wp_head & wp_footer on single posts
- Should I use add_filter for functions in function.php of the theme?
- How to add a post slug to a url?
- Add data attribute to each li in menu
- Print last modified date only on posts
- Why does post-slug not get saved for drafts?
- How to make modifications only to certain elements of an HTML string on the server-side?
- How can I add a filter for specific categories on functions.php?
- How would I go about replacing this function in my child theme located in inc/template-tags.php
- Retrieve a value from Yoast SEO to use to set a default twitter card image honoring overrides
- Filter an WordPress Function in (general-template.php)
- How can I add a class to a nav li depending on URL?
- A way to export slug as meta tag
- Modify gform_other_choice_value for specific form and specific field in Gravity Forms
- Set “woocommerce_is_purchasable” to false for specific “$product->is_stock_status”
- Display Terms Comma separated and Hyperlinked
- Is it possible to create slug on homepage and how?
- Problem with images URL after filter applying
- remove_action not working, even after changing priority [duplicate]
- remove/hide wp-editor
- Add a class to post if it has been recently updated
- search form leads to 404
- how to add_filter to non hook function
- Change Default Content when Creating a Post based on Previous Category Choice
- Adding tables to dashboard pages programmatically?
- Category Slugs = 404s?
- How to assign php file(template) to several pages with same prefix page name/slug
- How to prevent post_name from incrementing in wp_insert_post?
- Test the existence of a page/article by its URL, taking in consideration the URL rewriting by filters
- How to remove get_header From all single pages in wordpress with functions.php without plugin?
- Overwrite text in a complicated filter hook
- Change lost password url to a mailto URL in WordPress
- Save_post – Warning: Cannot modify header information
- Remove span tags from WooCommerce Downloads page
- How Can I Create a Friendly Slug for a Dynamic Page?
- custom error message for empty username and password using authenticate filter not working
- Add #primary at the end of navlink permalinks on single posts
- How to add a custom class attribute into code wrapper? [duplicate]
- only update titles of single posts
- OOP Switch statement with array as parameter
- Hide a specific category title from displaying on site
- Modify function output in a plugin
- Reload page with a different shortcode when a user selects from a dropdown
- How can I automatically delete comments that contain a URL?
- Appending „read more” to the excerpt conditionally
- How to add class dynamically from templates
- WordPress Ajax filter: Create two loops for different output styles?
- Override filter variable not working
- ACF Filter return value
- How to remove title tag with this filter
- Default post category overruling %category% setting for posts URL
- WordPress page not showing up – replaced with last 10 posts?
- str_replace not preserving whitespace
- How to make an If Else on Excerpt Filter
- Regex works in regexr, but not if I filter content [closed]
- Retrieve a custom form field modified by a filter
- WordPress permalink setting
- Woocommerce Price Text
- Limit Taxonomy Parents
- Display a post based on its metabox selection
- How to Disable UNICODE slug?
- apply_filters to featured image
- Force resize for all video content
- Way of getting queried loop before the query with a filter hook?
- Including inline Custom Fields info with add_filter in functions.php
- add query string to all pages after user logged in
- Trying to get this function to show below the content
- WordPress v3.1 Has Character Encoding Issue With Title/Permalink?
- Ultimate get current page’s slug function
- How to Add Extra Text In WordPress Title Before Post Publish
- function to show youtube videos within excerpt – if condition and apply_filters
- How to create extra SUB ARCHIVE for each page?
- Slug is already taken – how do I find the original item