Displaying Logged-In User Name in WordPress Menu

I’m using WordPress with UserPro, and want my menu to display the logged-in user’s first name, linked to the user profile page. The problem is that in my menu structure, the “Profile” menu option is supposed to have a sub-menu containing “edit profile”, “submit”, and “logout”. This is the code I’m currently using: /*earlier code, … Read more

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

I’m trying to add a class to anchor links of children element in wp_nav_menu both for pages and posts. Is there a way to modify the Nav Menu Walker and do so? Basically my custom walker looks like this: class Main_Nav extends Walker_Nav_Menu { function start_lvl(&$output, $depth) { $indent = str_repeat(“\t”, $depth); $output .= “\n$indent<ul … Read more

WP_Query and next_posts_link

I cannot figure out how to make next_posts_link() work within my custom WP_Query. Here is the function: function artists() { echo ‘<div id=”artists”>’; $args = array( ‘post_type’ => ‘artist’, ‘posts_per_page’ => 3, ‘paged’ => get_query_var( ‘page’ )); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); echo ‘<a class=”artist” href=”‘.get_post_permalink().'”>’; echo ‘<h3 … Read more

How to use the_posts_navigation for wp_query and get_posts?

WordPress have the_posts_navigation function since 4.1.0. But I don’t know how to use with wp_query or get_posts. the following code is in a template file of page.wp_query method: <?php if ( get_query_var(‘paged’) ) { $paged = get_query_var(‘paged’); } else if ( get_query_var(‘page’) ) { $paged = get_query_var(‘page’); } else { $paged = 1; } $get_posts=new … Read more

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

I want to modify the WooCommerce “My Account” left side navigation menu. For that, I have made changes in the woocommerce/templates/myaccount/navigation.php. The problems with this approach are: I can add the new items only at the first or last position in the menu. I’d need them at the 2nd and 3rd position instead…. If WC … Read more

Add custom classes to anchor in wp_nav_menu

I want to add a custom class to anchors in wp_nav_menu outputs. Default for example is: <li id=”menu-item” class=”menu-item menu-item-type-custom”> <a href=”http://example.com”>example</a> </li> I want this : <li id=”menu-item” class=”menu-item menu-item-type-custom “> <a href=”http://example.com” class=”class”>example</a> </li> 4 s 4 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( … Read more

How to add CSS Class to previous_post_link or get previous/next post link URL

How can I add a CSS Class to the previous_post_link output or just get the URL and create the HTML markup myself 6 s 6 You can use the more native function that is “below” the previous_/next_post_link();: # get_adjacent_post( $in_same_cat = false, $excluded_categories=””, $previous = true ) $next_post_obj = get_adjacent_post( ‘”https://wordpress.stackexchange.com/questions/17218/,”‘, false ); $next_post_ID = … Read more