Skip to main content
28 votes
Accepted

How to modify navigation menu of the "My Account" page in WooCommerce

For that, you do not need to modify the woocommerce/templates/myaccount/navigation.php. The best way to customize the "My Account" navigation menu items is to use: woocommerce_account_menu_items ...
ClemC's user avatar
  • 1,965
27 votes
Accepted

Add custom classes to anchor in wp_nav_menu

You can do this with the nav_menu_link_attributes filter. add_filter( 'nav_menu_link_attributes', 'wpse156165_menu_add_class', 10, 3 ); function wpse156165_menu_add_class( $atts, $item, $args ) { ...
cjbj's user avatar
  • 14.6k
17 votes
Accepted

How to give paged links custom title?

Here's a way to support pagination titles of the form: <!--nextpage(.*?)?--> in a simlar way as the core supports <!--more(.*?)?-->. Here's an example: <!--nextpage Planets --> ...
birgire's user avatar
  • 67.4k
14 votes

How to Add <span> to Each Menu Link with link text to data-attr?

Since version 4.4.0 the 'nav_menu_item_args' filter was added. This allows you to set 'link_before' and 'link_after' attributes for each item. add_filter('nav_menu_item_args', function ($args, $item, ...
Daren Zammit's user avatar
8 votes

Displaying Logged-In User Name in Wordpress Menu

The code: function give_profile_name($atts){ ... } gives a warning. Better is: function give_profile_name(){ ... } And it is better to detect if the user is logged in or not. Like so: function ...
Eutychus Mak's user avatar
8 votes

Main menu not appearing on category pages

I know this question is quite old but since there is no answer yet an there are many similar questions on the WordPress support forums, I'll better share my findings and maybe help someone. The issue ...
AndyDeGroo's user avatar
8 votes
Accepted

Removing link '<a>' from '<li>' menu for some "links" without JS

Assuming you're using wp_nav_menu() to display your navigation you could apply a walker that looks for css classes: $items_wrap = '<nav class="...">'; $items_wrap .= '<ul id="%1$s" class="%...
Howdy_McGee's user avatar
  • 20.7k
7 votes

How to add menu support to a theme?

Put this pretty much anywhere (ie. functions.php) add_theme_support( 'menus' );
Joel M's user avatar
  • 427
7 votes

Get the children of the parent category

Use the code below in your archive.php file. This code will help you: $term = get_queried_object(); $children = get_terms( $term->taxonomy, array( 'parent' => $term->term_id, '...
Violla Queue's user avatar
6 votes

Displaying Logged-In User Name in Wordpress Menu

No shortcode needed add_filter( 'wp_nav_menu_objects', 'my_dynamic_menu_items' ); function my_dynamic_menu_items( $menu_items ) { foreach ( $menu_items as $menu_item ) { if ( strpos($...
Manu Lebranders's user avatar
6 votes

Remove current_page_parent nav class from blog index when in CPT

The current answer is great but it assumes the title of blog's navigation item is "Blog". This could cause problems if the a user ever modifies the nav item in WordPress. The following code is ...
richk's user avatar
  • 61
6 votes
Accepted

How can I limit the length of the previous/next posts in my Wordpress Theme?

Here's a little coding that should implement this for you: <?php $max_length = 5; // set max character length here $next = get_next_post()->ID; $prev = get_previous_post()->ID; if( $prev ) ...
Ismail's user avatar
  • 1,936
6 votes

How to modify navigation menu of the "My Account" page in WooCommerce

Well customizing Woocommerce account and adding new items comes in a few steps, First Step: Create Links: You should use woocommerce_account_menu_items filter to modify existing menu items or adding ...
Amin Abdolrezapoor's user avatar
6 votes
Accepted

PHP 7 - Class Method Compatibility Issue

You must have the same function arguments in functions on class inheritance. So replace function update() with update($new_instance, $old_instance) in your code
Anton Lukin's user avatar
6 votes
Accepted

Add class to active top level (grandparent) menu item

Styling the top-level item if it's active or a child is active is possible with pure CSS. Use the child selector, >, from the top: .sidebar-navigation > ul > .current-menu-item, .sidebar-...
Jacob Peattie's user avatar
5 votes

How to give paged links custom title?

You can use filter wp_link_pages_link First pass our custom string placeholder (This can be anything you like except string containing %, just for now I am using #custom_title#). wp_link_pages( ...
Sumit's user avatar
  • 4,804
5 votes
Accepted

Number of items in a menu

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 ...
birgire's user avatar
  • 67.4k
5 votes
Accepted

Add Page ID class to nav menu items

We can add custom nav menu classes through the nav_menu_css_class filter. Example: The following should add the CSS class wpse-object-id-{object_id} to the <li> tags: // Add filter add_filter(...
birgire's user avatar
  • 67.4k
5 votes

Move WP Admin Bar

The admin bar is hooked to wp_footer. So … remove_action( 'wp_footer', 'wp_admin_bar_render', 0 ); … will remove it from there. And then you can register it for a custom hook with: add_action( '...
fuxia's user avatar
  • 107k
4 votes

wp_nav_menu: check if the list item has children and add a class to anchor link

The other way is very simple and may be useful for some people /** * Custom Nav Classes * https://v123.tw */ add_filter('nav_menu_css_class' , 'v123_nav_class' , 10 , 2 ); function v123_nav_class ($...
Ann's user avatar
  • 141
4 votes

Add custom classes to anchor in wp_nav_menu

I have solution to add class to anchor tag. 1: Step: add this in functions.php function add_additional_class_on_a($classes, $item, $args) { if (isset($args->add_a_class)) { $classes['...
Mohammad Ayoub Khan's user avatar
4 votes

How to add text before WordPress menu item href

You'll want to use the following filter: nav_menu_link_attributes Example: function filter_nav_menu_link_attributes($atts, $item, $args) { if ( isset($args->theme_location) && $args-...
Adam's user avatar
  • 16.5k
4 votes
Accepted

Get menus created with menu editor?

Maybe this helps : function get_all_wordpress_menus(){ return get_terms( 'nav_menu', array( 'hide_empty' => true ) ); } get_registered_nav_menus only gets the theme's menu's and not the ...
CompactCode's user avatar
4 votes
Accepted

Third level navigation class

You don't need to write your custom Walker for that... Let's take a look on built-in Walker_Nav_Menu. You'll find this function: public function start_lvl( &$output, $depth = 0, $args = array() )...
Krzysiek Dróżdż's user avatar
4 votes
Accepted

add another html tag after li element in wp_nav_menu

When using wp_nav_menu() you can exclude the <ul> tag by setting the items_wrap to only include the list items (%3$s), then you can add your own <li> before or after that, and wrap it with ...
Jacob Peattie's user avatar
3 votes

Navigation (wp_nav_menu) refuses to nest within parent element

'echo' => true needs to be 'echo' => false in your wp_nav_menu array for it to nest. From the docs you'll find 'echo' (bool) Whether to echo the menu or return it. Default true. so what's ...
FellowTraveler's user avatar
3 votes

Remove current_page_parent nav class from blog index when in CPT

Ok both answers are not very elegant because you have to enter the CPTs name manually. Here is a simple drop in snippet. It is pretty much copied from here so kudos to that site. This snippet removes ...
GDY's user avatar
  • 428
3 votes

How can I limit the length of the previous/next posts in my Wordpress Theme?

This can be done just using simple css based on max-width and text-overflow properties. <style> /** * note that your theme might not use class nav_posts * so you might have to ...
Antony Gibbs's user avatar
3 votes

Show posts count for Categories and Tags in wp_nav_menu

Alright so this isn't too difficult, first we will just check if the menu item is a taxonomy then get the count and display it! function ggstyle_menu_item_count( $output, $item, $depth, $args ) { ...
ngearing's user avatar
  • 2,164

Only top scored, non community-wiki answers of a minimum length are eligible