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
- Is there anything that Joomla or Drupal can do that can’t be done in WordPress? [closed]
- Removing Metabox for “Slug” without removing functionality
- Any post install tips after installing WordPress 3.0.1?
- Maintaining synced staging/production WP sites
- WordPress Multi Site Best Practice
- Sub posts and non unique post_name
- How to let a single post have its own domain name
- How to instantly delete posts/pages permanently?
- How to re-arrange media uploaded using : media_handle_upload() as per year / month
- How could we customize the all posts page in the admin panel?
- Adding Pagination on a Custom Author Page
- How to provide a demonstration of WordPress for new customers
- Showcase elementor templates
- Add clickable arrows to parent menu items with children elements e.g. with
- Woocomerce custom billing address fields display in order details [closed]
- Bind JS event to WordPress control customizer
- How can I setup up an a pre-populated pdf based on what was entered? [closed]
- Get rid of title from static front page
- Make custom page look exactly as homepage
- $wpdb->insert running multiple times?
- Why does my Posts page only show a single post when using Thematic?
- Specific colours for wordpress author ids
- How to unpixelate logo?
- Remove header title form page through CSS [closed]
- Attach File Funcion for Common people
- Conflict between Yoast SEO and my custom theme
- How do I target this page specifically?
- Local Shortcode Using WordPress Custom Fields
- Page Permalinks: Custom URLs
- How to send email with wp_mail() with from email taken from contact form instead of the host?
- Change post template the proper way
- ACF Shortcode bringing in my shortcode is adding unnecessary line breaks
- Custom single page based on which custom page template is selected
- Custom MySQL query to list post
- menu customization
- How to stop login for SPECIFIC users BEFORE a specified date
- Woocommerce send custom email receipt based on product attribute
- Local WordPress installation feeding multiple online site sites
- Redirection after Category Change for Custom Structure
- How to move custom icons from parent theme to the child theme