New answers tagged

2

These are almost certainly custom post types. In the definition of the custom post type, it is possible to define a menu_icon which can be a file or an icon from the iconfont. It is this menu_icon that is showing up in your admin menu. I also notice "Programs Categories" in your menu, this looks like a custom options page - which will have also been ...


1

It's called "event bubbling" or "event propagation" and the solution is to get the event object and use the JS stopPropagation method. Try this: jQuery('.menu-item').click(function(event){ var class_id = jQuery(this).attr('id'); event.stopPropagation(); alert(class_id); });


2

This should add the drop class to all the li elements in the menu and also add your classes to the wrapping ul: function wpse_232637_add_menu_parent_class( $items ) { foreach ( $items as $item ) { $item->classes[] = 'drop'; } return $items; } add_filter( 'wp_nav_menu_objects', 'wp_232637_add_menu_parent_class' ); $args = ...


0

I believe that you have neglected to create a menu on the Appearance > Menus panel in the WordPress admin dashboard and associate it with your registered 'header-nav' menu location. If I'm correct, the possible solutions might sound a little strange. Simply create a menu - the extraneous <div> should disappear even if you don't associate the new ...


1

one problem exists there... Wordpress has built-in page detection, to give the CSS classes to current page in menu... and if cached, then your navigation menu-items will never get "current-page" class or etc.. however, there are 2 solutions: Solution 1 Before caching, once, add classes to <a> items: function add_menu_atts( $atts, $item, $args ) { ...


0

You can use this code and it will really help you a lot <?php require( '../wp-load.php' ); get_header(newtheme); echo 'new content outside WordPress'; get_footer(); ?>


0

I checked out the walk method from the original Walker class source at WordPress and used that to get my result. I added a couple of more things to it, including: Adding first and last classes to the every ul in the navigational menu. Adding odd and even classes to every li relative to the position it is in its ul. Adding before-parent and after-parent ...


1

https://developer.wordpress.org/reference/hooks/wp_nav_menu_menu-slug_items/ function my_nav_menu_primary_navigation($items, $args) { $items .= '<li>Hello :D</li>'; return $items; } add_filter( "wp_nav_menu_{MENU SLUG}_items", "my_nav_menu_primary_navigation", 10, 2 ); find {MENU SLUG} EDIT: The "wp_nav_menu_menu-slug_item" filter ...


0

EDIT: I tried the following and it works in the theme "Storefront for woocommerce"(Though it needs additional styling). For some reason though, it does not work well with the twentyfifteen theme.(The submenu does not show.) add_filter( 'wp_nav_menu_items', 'wc_products_on_nav_menu'); //filter to add the html add_action( 'save_post_product', '...


1

Thanks for the help birgire. That gave me a lot to think about. Eventually I have came up with a solution using a filter I can count the number of parents the menu has. The only problem with this approach is that it will run every time a menu is displayed. function my_nav_menu_objects($sorted_menu_items, $args) { if($args->menu == 'header_menu') { ...


0

go into your wp-config.php file and look for this line: define('WP_DEBUG', false); change false to true and it should give you a better idea of what's going on. otherwise, deactivate plugins one at a time to see if a plugin is causing the problem.


5

I was curious and decided to check it out, regardless if it's relevant for a CSS problem ;-) I first peeked into the database tables to find more about the menu structure: Menu - building blocks Each navigational menu is registered as a term in the nav_menu taxonomy. Then when we add items to that menu, we are creating new post objects of the type ...


0

You can try to alter the $attributes string, since that outputs the attributes in the a tag. The following is untested: $myClass = 'some-custom-class'; $myClassAdded = false; $attributes = ''; foreach ( $atts as $attr => $value ) { if ( ! empty( $value ) ) { $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); if( $...


-2

<?php //simple wordpress loop $loop= new WP_Query( array( 'post_type'=>'post', 'orderby'=>'ID', ) ); if($loop->have_posts()): while($loop->have_posts()): $loop->the_post(); ?> //all the stuffs you want to put in <a href="<?php the_permalink(); ?>"><h2>...


-2

Use get_posts with posts_per_page => 1 to get only one latest result. You can than use get_permalink() to get the permalink. $args = array( 'posts_per_page' => 1, 'orderby' => 'date', 'order' => 'DESC', ) ; $latest_posts = get_posts($args); $permalink = get_permalink($latest_posts[0]->ID);


0

Use the get_search_form filter: add_filter('wp_nav_menu_items','add_search_box_to_menu', 10, 2); function add_search_box_to_menu( $items, $args ) { if( $args->theme_location == 'primary' ) return $items. get_search_form(); return $items; } add_filter( 'get_search_form', 'custom_search_form' ); function custom_search_form( $form ) { ...


0

From the WP-Admin. Click on Appearance > Menus In the top right, click "Screen Options" Select (check) "CSS Classes" Then you will have added the optional "CSS CLASSES" to each menu item.



Top 50 recent answers are included