Adding theme option values as custom body class

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

body_class(); not working with bootstrap navbar fixed top?

Why not use a navwalker to create your bootstrap menu? Try https://github.com/wp-bootstrap/wp-bootstrap-navwalker You can get the fixed-top to add to the menu <nav class=”navbar navbar-default navbar-fixed-top” temscope=”itemscope” itemtype=”http://schema.org/SiteNavigationElement” role=”navigation”> <div class=”container”> <div class=”navbar-header”> <button type=”button” class=”navbar-toggle” data-toggle=”collapse” data-target=”#navbar”> <span class=”sr-only”>Toggle navigation</span> <span class=”icon-bar”></span> <span class=”icon-bar”></span> <span class=”icon-bar”></span> </button> </div> <div class=”collapse navbar-collapse” id=”navbar”> <ul class=”nav … Read more

Add a class with body_class to a specific url with parameter

You’re overcomplicating it a bit. ?um_action=edit is a query string, and its values are available in the $_GET superglobal. To check if it exists, and has a specific value, you just need to do this: function leweb_add_body_class_um_edit_profile( $classes ) { if ( isset( $_GET[‘um_action’] ) && ‘edit’ === $_GET[‘um_action’] ) { $classes[] = ‘leweb-um-profile-edit’; } … Read more

Add class to website based on post taxonomy

You can use the body_class filter in WordPress to add the Taxonomy Terms of a Custom Taxonomy as CSS classes to a post. The CSS class appears in the body element and is only used if the post has been assigned to the taxonomy. The code goes in your functions.php file. add_filter( ‘body_class’, ‘themeprefix_add_taxonomy_class’ ); … Read more

How to add order status class to the body tag?

This does the trick add_filter( ‘body_class’, ‘order_class’); function order_class( $orderclasses ) { $user_id = get_current_user_id(); // The current user ID // Get the WC_Customer instance Object for the current user $customer = new WC_Customer( $user_id ); // Get the last WC_Order Object instance from current customer $last_order = $customer->get_last_order(); $order_id = $last_order->get_id(); // Get the … Read more

How do I add Category Body Classes to Admin?

You’re using $post->ID which is undefined. Try $_GET[‘post’] instead: // Get Categories if ( is_admin() && isset($_GET[‘post’]) ) { $cats = wp_get_post_categories( (int)$_GET[‘post’], array( ‘fields’ => ‘all’ ) ); $cats = wp_list_pluck( $cats, ‘slug’ ); foreach ( $cats as $cat ) { $classes .= ‘ category-‘ . $cat; } }

Cannot set property ‘className’ of null at setThemeFromCookie

Using JQuery Simplifies the whole thing, using JS Cookie $(document).ready(function(){ // Check cookie and set theme if(Cookies.get(‘theme’)) { $(‘body’).removeClass(‘light-mode dark-mode’).addClass( Cookies.get(‘theme’) ); }; //Switch theme and create the cookie… $(“#theme-toggler”).click(function(){ if ($(‘body’).hasClass( ‘light-mode’)){ $(‘body’).removeClass(‘light-mode’).addClass(‘dark-mode’); Cookies.set(‘theme’, ‘dark-mode’); }else { $(‘body’).removeClass(‘dark-mode’).addClass(‘light-mode’); Cookies.set(‘theme’, ‘light-mode’); } }); }); Add id to button. <button id=”theme-toggler” type=”button” name=”dark_light” title=”Toggle dark/light mode”>🌛</button> … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)