To add the custom taxonomy slug to the body classes of your WordPress site, you can use the body_class filter along with your custom code. Below is your example of how you can achieve this:
function themeprefix_add_taxonomy_class($classes) {
global $post;
if (is_page()) {
$taxonomy = 'page_section';
$terms = get_the_terms($post->ID, $taxonomy);
if ($terms && !is_wp_error($terms)) {
foreach ($terms as $term) {
$classes[] = 'section-' . $term->slug;
}
}
}
return $classes;
}
add_filter('body_class', 'themeprefix_add_taxonomy_class');
Related Posts:
- Get wordpress taxonomy slug name(s) to use as div class
- If Term Name Exists, Append a Unique ID to Slug
- How to assign a default/priority taxonomy to be shown in url in case two taxonomy items are selected
- Custom taxonomy: same terms, but for different years
- Editing the Number at the end of Page URLs / Editing Page Slugs
- get_terms return errors
- How to show only Standard Format post in my custom taxonomy page -wordpress 3.8.1
- Reproducing hierarchical list output from wp_list_categories(), using get_categories()
- Fast way to add countries as a custom taxonomy term?
- WordPress 3.1 removing ‘category’ from the slug
- Is there a filter hook that I can use to change how taxonomy term names are displayed?
- How to Register and Display Widget for Custom taxonomy
- how to flush custom author rewrite rule
- Show Custom Taxonomy Slug(s)?
- Remove Author Slug & Replace With Username
- How can I get the page url slug when ‘post_name’ returns an id?
- Custom Taxonomy Archive not displaying entries
- Exclude custom taxonomy tag from loop
- Hide custom field if empty
- Filter posts by custom taxonomy terms
- Function to remove archive sidebar for custom taxonomy?
- WordPress slugs and 404 handling takes preference over folders in site root?
- Automatically check parents (in a taxonomy) when child is selected
- How to add textarea field to taxonomy (tag)?
- How can I get the custom post type assigned to a current custom taxonomy for query?
- wp_query get post custom taxonomy in search.php
- Remove Custom Post Type Slug and add Custom Taxonomy to Permalink Structure?
- Redirect to another page using contact form 7? [closed]
- How to get every custom taxonomy names and urls?
- Get Custom Taxonomy Terms by Date
- Display specific Taxonomy Term from Custom Post Type
- Don’t change Custom Post Type slug to unique value
- Semi complicated custom taxonomy question
- How do I list custom taxonomy terms with the links?
- How to display page ids as page slug names?
- Echo the Last Child Taxonomy only (not parents)?
- How to query term_id of a Custom Taxonomy by name
- How to show parent taxonomy using get_the_terms?
- wp_insert_post custom taxonomy multiple Category not added
- query variables for custom taxonomies
- Display all subterms of a custom taxonomy filtered by parent terms
- My list of terms of custom taxonomy displays 7 times
- Adding a custom field to a slug
- Display Custom Taxonomy Name As A Shortcode
- Taxonomy template is not reading
- URL issue after setting up Custom Structure in Settings >> Permalinks
- Post filter with multiple checkbox taxonomy terms
- Combine Categories & Custom Taxonomy
- Custom dropdown search form that allows users to select option B based from Option 1
- issue with saving custom metaboxes fields
- Taxonomy template by post type
- How to loop through 1 CPT with 2 Taxonomies
- Custom terms in custom category taxonomy
- How to keep the /blog slug even in single post slug
- How to setup a taxonomy that can have only one post assigned to it?
- Grouped custom taxonomy query
- Create advanced portal website with sections – taxonomy usage?
- Custom Query for Taxonomy
- Adding a third custom taxonomies
- Taxonomy question how to add more data
- Use Theme CSS in custom code
- How to get the full product name by ignoring custom modification on it
- adding fade on mouseover to images
- where is admin footer?
- Customize section does not show my widget areas
- How can i add customisation of text to my theme?
- Add producthunt badge to wordpress menu
- Can I overwrite custom taxonomy FROM “public” TO “false”
- Show products per page drop down
- Trying to customise 2011 Child Theme Background Colour
- How to remove (…) from the post tilte on homepage?
- Is it possible to edit a wordpress category with Gutenberg?
- Widget recent comment filter by post meta_value
- Invitation link to a site in multisite network does not work?
- Swap home page based on user role, Elementor layout breaking
- Add helper text in custom-header section in admin
- How to edit content in code view of home page when there is some theme applied?
- How to display strikethrough text in button text (for special offer)
- Adding shortcode to product short description
- How to change Login default blue admin color?
- Remove Title and White Space in Twenty Twenty theme
- How do i remove this from logged in users?
- Schedule a subscription on gravity form, stripe add-on
- How to show related post with category DESC (ASC) IDs of ID current post
- Lost customization after switching the WordPress theme
- How to show Term ID beside Name Category with wp_dropdown_categories()
- Gender based user avatar
- Migrating my site to a new domain does not keep any changes made in customizer
- Woocommerce custom “My Account” Tab – Add Save button
- How to create custom backend admin menu in different languages?
- WordPress Using Zip code customer shop find without woocommerce plugin
- Is MultiSite the Correct Solution for a Corporate Site with Searchable Regions?
- How can I style the Comment Section of a blog post
- New to WP: links on static homepage are not working
- Custom Meta Box: Value saved in WordPress DB, but not shown in input field on Edit Screen
- Conflict between Yoast SEO and my custom theme
- Custom post-type working except for Selecting page-parent
- Need to add custom text field to Woocommerce under add to cart button
- How to show the hero of website when sending website link?
- How can I display both LTR and RTL language texts on the same page?