add class to all images inside the content
$img->setAttribute(‘class’, ‘img-fluid’); This sets the class field to a new value. Simply change this line to $classes = $img->getAttribute(‘class’); $img->setAttribute(‘class’, $classes . ‘ img-fluid’);
$img->setAttribute(‘class’, ‘img-fluid’); This sets the class field to a new value. Simply change this line to $classes = $img->getAttribute(‘class’); $img->setAttribute(‘class’, $classes . ‘ img-fluid’);
Adding body class in author page for custom role
you could try to use this: add_filter(‘body_class’, ‘custom_body_class’); function custom_body_class($classes) { global $post; if ($post->ID == 346) { $classes[] = ‘services’; } return $classes; } This can be used anywhere as its pulling the global variable first.
found it: add_filter( ‘body_class’, ‘dc_parent_body_class’ ); function dc_parent_body_class( $classes ) { if( is_page() ) { $parents = get_post_ancestors( get_the_ID() ); $id = ($parents) ? $parents[count($parents)-1]: get_the_ID(); if ($id) { $classes[] = ‘top-parent-‘ . $id; } else { $classes[] = ‘top-parent-‘ . get_the_ID(); } } return $classes; }
add_filter ‘body_class’ only working for logged in users
How to insert the current user’s role into the body class in the admin backend
How to override Plugin javascript function : $(‘body’).on(‘change’,’.class’)
This works for the admin backend; I needed to restructure the filter to be able to add a priority: function add_admin_body_class($classes) { $user = wp_get_current_user(); foreach ($user->roles as $user_role) { $classes .= ” role-{$user_role}”; } return $classes; } add_filter(“admin_body_class”, “add_admin_body_class”, 9999);
Blog page (aka posts page) corresponds to is_home() conditional, which you are excluding. is_home() is often at site root, but blog page configured to be elsewhere is exactly the case when it isn’t.
Review how the variable scope works.. Let’s not add yet another global variable, instead we can e.g. fetch the option values within the filter’s callback: function wpse251261_custom_body_classes( $classes ) { // Get option values $rounded_corner_radio = of_get_option( ’rounded_corner_radio’ ); $gradient_radio = of_get_option( ‘gradient_radio’ ); // Assign new body classes $classes[] = esc_attr( $rounded_corner_radio ); $classes[] … Read more