Remove Body Classes

One (untested) suggestion is to replace: unset( $classes[array_search($body_classes, $classes)] ); with $classes = array_diff( $classes, wp_parse_slug_list( $body_classes ) ); assuming the classes survive sanitize_title from wp_parse_slug_list(). It should also be alright with empty arrays. We also note that wp_parse_slug_list() is using wp_parse_list() to parse the comma separated string.

create a page which displays a list of categories title+ short description?

You just need to add some conditional to aplly the filter or not. For example, if you don’t want to apply the trimming on category archive pages, one possible solution could be: add_filter( ‘category_description’, ‘cyb_trim_category_desc’, 10, 2 ); function cyb_trim_category_desc( $desc, $cat_id ) { // Apply only if we are not in category archive template … Read more

Handling Body class based on Template

I’m not sure if I understand your question correctly, but… If you want to set body classes based on current page, then you can use this code function my_body_class( $classes ) { if ( is_home() ) { $classes[] = ‘wbody’; } else { $classes[] = ‘gbody’; } return $classes; } add_filter( ‘body_class’, ‘my_body_class’ ); Of … Read more

Add category to body class

This late in the process you should be able to rely on context set up, even outside of loop. On top of my head something like this should work: $categories = wp_get_post_categories( get_the_ID(), [ ‘fields’ => ‘names’ ] );

category hierarchy level as a body class – parent cat =1, child cat=2, grandchild=3

You can achieve this by using the following custom code. You can use the code by adding it in the functions.php file of child theme or in the custom plugin file. add_filter( ‘body_class’, ‘custom_cat_archiev_class’ ); function custom_cat_archiev_class( $classes ) { if ( is_category() ) { $cat = get_queried_object(); $ancestors = get_ancestors( $cat->term_id, ‘category’, ‘taxonomy’ ); … Read more

De-bloating the page classes

And the answer is like this; I figured the most useful bits for me was something that read like this; <body class=”page my-page page-id-28 template-mypage”> where page is the post type, mypage is the page slug, then the id and finally an elegant form of the template. (my templates are all of the form page-templates/page-mypage.php … Read more

I am adding a new class to my body tag if the logged in user is subscriber, need help

Please try this code instead- add_filter( ‘body_class’, ‘wpse_268176_body_class’ ); function wpse_268176_body_class( $classes ) { $user = wp_get_current_user(); if ( in_array( ‘subscriber’, $user->roles ) ) { $classes[] = ‘class-name’; // your custom class name } return $classes; } Place this in your active theme’s functions.php file. [Thanks Dave Romsey for your suggestion.]

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)