How to check custom fields from functions.php

I don’t know if you need to hide the element completely, as in “never display it”, or if you need to hide it conditionally with JavaScript– say, to get a toggle effect. Either case is similar and would use get_post_meta(). To conditionally display the data use something like: $m = get_post_meta(get_the_ID(),’my_meta_key’); if(!empty($m)) { echo ‘<div>your … Read more

Show post titles within WordPress bootstrap Dropdown menu

Thank you for our reply i solved my problem i used WordPress loop query for showing last fout posts in four column as below if (!empty($item->divideto_4)) { $col = 3; $divide_to = 12 / $col; //4 $my_query = “showposts = “.$divide_to; $my_query = new WP_Query($my_query); while ($my_query->have_posts()) : $my_query->the_post(); $item_output .= ‘<div class=”col-sm-‘.$col.'”>’; $item_output .= … Read more

Current menu item class issue

You can use the nav_menu_css_class filter to alter the classes added to navigation items. You need to check the current menu items URL against the URL of the page you are on. add_filter( ‘nav_menu_css_class’, ‘wpse_217882_menu_class’, 10, 2 ); function wpse_217882_menu_class( $classes = array(), $item = false ) { // Get current URL $current_url = wpse_217882_current_url(); … Read more

How to add custom nav_menu_css_class to certain menu only?

You just need the third argument $args, of which one of it’s properties is theme_location: function wpse_218377_nav_menu_css_class( $classes, $item, $args ) { if ( ! empty( $args->theme_location ) && $args->theme_location === ‘custom-menu’ ) { $classes[] = ‘footer–menu-item’; } // ALWAYS return, not from inside the if return $classes; } add_filter( ‘nav_menu_css_class’ , ‘wpse_218377_nav_menu_css_class’ , 10, … Read more

Insert menu into theme location depending on user logged in/out status

Okay, figured it out! I’ve amended my theme function as follows: add_filter( ‘wp_nav_menu_items’, ‘add_loginout_link’, 10, 2 ); function add_loginout_link( $items, $args ) { if (is_user_logged_in() && $args->theme_location == ‘top_navigation’) { $items .= wp_nav_menu( array(‘menu’ => ‘menu-logged-in’, ‘container’ => ”, ‘echo’ => false, ‘items_wrap’ => ‘%3$s’) ); } elseif (!is_user_logged_in() && $args->theme_location == ‘top_navigation’) { $items … Read more