Why does admin_body_class not work?

I'm trying to add the body class of the current user role to both the frontend and the admin backend. Why does admin_body_class not work for admin? The comment to this question does not work: How to insert the current user's role into the body class in the admin backend This works for the front end in the theme's functions.php file: add_filter("body_class", function($classes) { global $current_user; foreach ($current_user->roles as $user_role) { $classes[] = "role-{$user_role}"; } return $classes; }); This does …
Category: Web

Creating custom post-listing templates in twentyseventeen child theme

I'm using a child theme based on 'Twenty Seventeen' and have created a custom post type ('review'). I want to make two Pages, one which lists 'reviews' and the other which lists a mixture of 'posts' and 'reviews' (ordered by recency). For the first of those I've made a copy of Twenty Seventeen's index.php, as page-reviews.php, and added code like this at the start: $args = array( 'post_type' => 'review', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => 10, ); …
Category: Web

add css to only body text

In my single wordpress posts I want to apply a padding of 100px to the left and right. The problem is that when I apply it to .single .post-content the images also get a padding. However, I want all of the images on the posts pages to be set to 100%. Is there a way to separate the actual body text and the images? This seems like a fairly simple question. But I can't figure it out. Any help is …
Category: Web

Custom Taxonomies in body class with parent slug

I have tried many answers here on stackoverflow but couldnt find a solution to my problem. I have created a custom post type called ph_products and custom taxonomies with the name ph_category. Then I created some categories for that custom post type like this: blue-products blue-sub-products green-products red-products I need to have body classes as following: When on the ph_products-archive page there should be a class with that slug in the body When on one of the parent categories the …
Category: Web

How to override Plugin javascript function : $('body').on('change','.class')

EDITED: Extensively rewritten after some research Requirement I need to override a script in the custom.js of a 3rd party plugin. $('body').on('change', '.wpt_row input.input-text.qty.text', function() { (some javascript code here) }` What I know so far I need to: dequeue the plugin script in /wp-content/plugins/3rd-party-plugin/assets/custom.js and then enqueue my own script from /wp-content/themes/my-child-theme/includes/js/my_child_scripts.js To achieve this I must add something like this to my child theme functions.php: add_action('wp_enqueue_scripts', 'my_mod_script_load', 100); function my_mod_script_load() { wp_dequeue_script('THE_PLUGIN_SCRIPT'); wp_enqueue_script('MY_MOD_SCRIPT', get_stylesheet_directory_uri().'/js/scripts.js'); } Where I get …
Category: Web

How to insert the current user's role into the body class in the admin backend

I've tried updating this code from body_class to admin_body_class but it's not inserting the .role-author into the back end body class like it did with the front end body class... i'm guessing it's not as simple as replacing body_class with admin_body_class? add_filter( 'admin_body_class', function( $classes ) { if( is_user_logged_in() ) { $classes = array_merge( (array) $classes, array_map( function( $class ) { return 'role-' . $class; // Here we prepend the 'role-' string }, (array) wp_get_current_user()->roles ) ); } return $classes; …
Category: Web

Add a unique class to HTML tag/element

I know there is a body_class function for WordPress. But is there one (or a way) to add a class to the HTML element? My goal is to be able to add a unique class (or ID) to a page's HTML element. Currently my theme is adding the page-id-XXXX class to the body element, but I need a way to have a unique class or ID on the actual HTML element. I'd probably be fine having the page-id-XXXX also added …
Category: Web

How to add seperate classes to no-search-result and found-search-result pages on wordrpess search - is_search()

I want to add seperate body classes for no search result and found search result pages on wordrpess search. I used that code but it isn't working - > what's the error here and what is the solution add_filter( 'body_class', 'custom_class', 1 ); function custom_class( $classes ) { if ((is_home() && !is_front_page()) || (is_search()) || is_tag() || is_author()) { $classes[] = 'archive'; } if (is_singular('page') || is_404() || (is_search() && 0 === $wp_query->found_posts )) { $classes[] = 'single'; } return …
Category: Web

how to remove all body classes in wordpress

i am working on custom page templates. so i want to remove all body classes by one function only. i searched it for on net but not found any solution. is there anyone who can answer it. @Php Edit.. how to remove all page template classes except all other.. example - page-template, page-template-zx, page-template-zx-php etc. means all classes that starts with "page" word. problem is that i am using many page templates so i want to do this with one …
Category: Web

Add a searchbox to the body of a page

I'm creating a website in which I need that, when I click on one of the tabs of the specific menu, and it opens, this page contains a search box in its body. My question is how can I add this search box to the page, where can it be edited. I've now started using WordPress, I've been doing a search but I haven't found anything that specifically answers me.
Category: Web

add_filter 'body_class' only working for logged in users

The below code works fine for logged in users but not for non logged in users. How do I make it work regardless of user type? add_filter( 'body_class', 'custom_body_class' ); function custom_body_class( $classes ) { $classes[] = 'guest-author'; return $classes; } I have added this code to my functions.php file.
Category: Web

Need to put a script above </body> tag in header.php - WP 5.7.1

I need to put this script above the tag in the header.php. window.Futy = { key: '0000000000' }; (function (e, t) { var n = e.createElement(t); n.async = true; n.src = 'https://v1.widget.futy.io/js/futy-widget.js'; var r = e.getElementsByTagName(t)[0]; r.parentNode.insertBefore(n, r); })(document, 'script'); But with the new header.php and hooks and function.php I don't know how to do this. I'm not a developer. So please tell me in a easy way as possible
Category: Web

Add class to woocommerce checkout body based on filter

I am trying to add a class to a checkout page if the checkout contains a subscription renewal. Woocommerce provides wcs_cart_contains_renewal() to check. I am using this code but obviously missing something as it's not working. $cart_items = wcs_cart_contains_renewal(); if ( ! empty( $cart_items ) ) { add_filter( 'body_class','my_body_classes' ); function my_body_classes( $classes ) { $classes[] = 'renewal-order'; return $classes; } } Any help on how to make this work?
Category: Web

How to add order status class to the body tag?

do you know how can we add CSS class into the body tag when a user has an (any) order which is on pending payment status? I tried this one but no luck add_filter( 'body_class', 'order_class'); function order_class($orderclasses) { $order = wc_get_order( $order_id ); $order_status = $order-&gt;get_status(); if( is_page( 30 )) { $orderclasses[] = $order_status; } return $orderclasses; } Thank you
Category: Web

Add term of current custom post type to admin body class using admin_body_class

I am trying to add the current custom post type term to the body class of my WordPress admin page. So when I am viewing an existing custom post type that has been assigned a term it will add that term to the body class. I have found the following code but cannot get it to work for me: add_filter( 'admin_body_class', 'rw_admin_body_class' ); function rw_admin_body_class( $classes ) { if ( 'post' != $screen-&gt;base ) return $classes; global $post; $terms = …
Category: Web

Add top parent page id to body class

I need to have the top parent page id added to the body class of the pages. Homepage (id:10) - Sub page (id:11) -- Sub detail page (id:12) By default it's like: Sub page gets parent Id 10 in the body class. And Sub detail page gets parent Id 11 in the body class. What I need is that the sub page detail needs to get the upper top parent id added to the body class so that id 10 …
Category: Web

Add class to website based on post taxonomy

I want to write a class to the body of all pages posts and custom posts (IE entire site) I am using a front end editor that allows logged in users to edit posts and keep them out of the back-end. I have a custom post-type "emergency status" It contains one post with a taxonomy "status" It has the terms extreme, severe, very-high, high, moderate. I want to add a filter that checks the taxonomy of that post and then …
Category: Web

Add a class with body_class to a specific url with parameter

i try to add a class to the body for a specific page/url, which has a parameter at the end. the url looks like this: https://sample-site.com/user/37/?um_action=edit with my code, the class is also added to the url without parameter. i know why this is happening, but i dont have any other idea to get this to work. function leweb_add_body_class_um_edit_profile( $classes ) { global $wp; $current_url = home_url( add_query_arg( array(), $wp-&gt;request ) ) . '/?um_action=edit'; $profile_url = um_user_profile_url() . '?um_action=edit'; if …
Category: Web

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

I have some code that loops through all categories and: organize them on a Hierarchy of (parent) category and its child categories echo the titles +short description of each category +add "read more" link to the full content of that category . click on the read more of one of the child category should have lead to that category page with full content description checks if they have posts or not. displays a list of posts (excerpt+read more link) that …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.