Pages

Sep 10, 2019

Append custom class to body element in wordpress



Have you ever wondered how to add custom class to body in any wordpress plugin or page.
Place the below code to update/add new class with any conditions.


add_filter('body_class','append_body_class');
function append_body_class( $classes ) {

    if (is_singular('post')) {
 
    $classes[] =  'news-single';
 
}

 
  return $classes;
}

Fix to increase google page speed (google insight)



If you are stuck in finding a stable solution to score high in google insight pagespeed then there is a simple solution.
Open your function file and add these code :

<?php function motyw_botfix() { ?>

 //Include header scripts and external scripts
//Any kind of scripts that is impossible to break.

<?php }

if (!isset($_SERVER['HTTP_USER_AGENT']) || stripos($_SERVER['HTTP_USER_AGENT'], 'Chrome-Lighthouse') === false) {
add_action('wp_head','motyw_botfix');
}