Hello Friends, I hope you are doing good. Today we are sharing important information about how to add inline css code in WordPress site
Normally we use wp_head or wp_footer action hooks function to add custom css code on our website but it's not a right way to add css on your website.
If you want secure and bug free WordPress website then you must have need to follow the WordPress coding standard otherwise any hacker can hack your site very easily. If you follow started of WordPress coding then we can give a guarantee that your site will never hacked and site speed will also always good.
Now lets come on point how we can add inline custom css code our website by following standard of WordPress. You can add inline css code using wordpress wp_add_inline_style() hooks function. wp_add_inline_style() hooks function will give a secure way to add inline custom css code, no one can hack your function.
please use below sample code in your theme function.php file and do needful changes as per your requirement.
/* register enqueue style */ add_action( 'wp_enqueue_scripts', 'my_inline_style_func' ); if(!function_exists('my_inline_style_func')): function my_inline_style_func() { wp_register_style( 'my_inline_style', false); // false/file_path ( false = no css file dependency, file path = inline css will load after particular css file ) wp_enqueue_style( 'my_inline_style' ); //load shortcode style $csscode = ' body{background-color:#f5f5f5;} body a{color:#fff000;} ' wp_add_inline_style( 'my_inline_style', $csscode ); }