WordPress blog assign unqiue body class
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.
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
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
You can try this, $body_css_classes = get_body_class(); if ( in_array( ‘my-class’, $body_css_classes ) ) { /* DO THIS */ } else { /* DO THAT */ } For more details please check this.
The code isn’t working because you haven’t defined or retrieved the $current_user or $post variables from anyway. You’ve also got a ! here for some reason: !$current_user->ID, which will just break the condition. You need to use the appropriate functions to get their values, and also use is_single() to make sure you’re viewing a single … Read more
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
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
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
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; } }
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