How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
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.
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
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
About your issue in admin body class, WP Codex documentation admin_body_class, class as string ( not array ), there are some of your function like get_saved_network_option not returning true that cause $new_classes not setted in array. This code correct, we need return in string, but $new_classes maybe in string empty or not array. return $body_classes … Read more
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’ ] );
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
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
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.]
I don’t think that there is a much smarter way to write this code in a procedural style, so basically your code looks okay. But there’s a logic error in your body_class_before_header() function which might cause the issue: If the conditional block is not executed, the function will return NULL but as it is a … Read more