Edit HTML of WordPress navigation bar

Yes, you’ll need to implement the walker class for this. Here is a simple example. $defaults = array( ‘theme_location’ => ‘primary’, ‘container’ => ‘ul’, ‘menu_class’ => ‘nav navbar-nav main-nav’, ‘walker’ => new Primary_Walker_Nav_Menu() ); wp_nav_menu( $defaults ); In the above block of code, the wp_nav_menu() function takes $defaults as argument. In the array $defaults, the … Read more

Add custom attributes to menu items without plugin

Filter nav_menu_link_attributes: add_filter( ‘nav_menu_link_attributes’, ‘wpse_100726_extra_atts’, 10, 3 ); function wpse_100726_extra_atts( $atts, $item, $args ) { // inspect $item, then … $atts[‘custom’] = ‘some value’; return $atts; } This works with WordPress < 3.6: add_filter( ‘walker_nav_menu_start_el’, function( $item ) { $parts = explode( ‘>’, $item ); $out = array (); foreach ( $parts as $i => … Read more

How to get a different mobile menu than desktop menu in the twentytwelve child theme

As recommended in a similar post: https://wordpress.stackexchange.com/a/156494/74343 1.) Create the menus as you want them, and name them as you like, as an example “mobile-menu” and “desktop-menu“. 2.) In your child theme in the header.php you could switch according to the wp_is_mobile() flag like this: if ( wp_is_mobile() ) { wp_nav_menu( array( ‘menu’ => ‘mobile-menu’ … Read more

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 ) { $title = get_the_title( $prev ); $link = get_the_permalink( $prev ); $post_name = mb_strlen( $title ) > $max_length ? mb_substr( $title, 0, $max_length ) . ‘ … Read more

How do I retrieve menu items from one level only?

Are you trying to display the posts from the top down a certain number of levels? If so, use wp_nav_menu. It has an argument “depth” built just for this and it works painelssly. wp_nav_menu(array(‘depth’ => 2)); Also, http://codex.wordpress.org/Function_Reference/wp_nav_menu

How to move parent li to end of child ul

Since this is a stylistic change, and not looking to reorder the DOM for semantic reasons, I think the js solution wouldn’t be the best approach. Better to keep it in CSS, keeping the markup intact. Two ways to do it: Flexbox: #generalinfo{ display: flex; flex-direction: column-reverse; } CSS Grid: #generalinfo{ display: grid; } .cat{ … Read more

Bootstrap dropdown nav pills not working with wp_nav_menu()

I ran into similar problem when I created a bootstrap navigation menu and dropdown links were all showing up at once. I used the following steps to correct the issue: download navwalker from github repo link: https://github.com/wp-bootstrap/wp-bootstrap-navwalker put this file in the root folder of the theme and in the functions.php file userequire_once get_template_directory() . … Read more

Getting the Next and Previous Posts Titles in the Sidebar?

The existing WordPress functions are only for displaying one previous or next post. I quickly wrote functions to display any number of posts. Paste the following in your theme functions.php file: function custom_get_adjacent_posts( $in_same_cat = false, $previous = true, $limit = 2 ) { global $post, $wpdb; $op = $previous ? ‘<‘ : ‘>’; if … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)