Extend walker – navigation, adding data attribute to a tag

This is how I added data attribute to my menu It simply adds data-title=”menu-title” to each link on my main nav, change it to adapt to your need. You don’t actually need to use Nav Walker to add this add_filter( ‘nav_menu_link_attributes’, ‘cfw_add_data_atts_to_nav’, 10, 4 ); function cfw_add_data_atts_to_nav( $atts, $item, $args ) { $atts[‘data-title’] = $item->post_title; … Read more

How to Create a Custom WordPress Navigation Menu with the Code?

Well first of all you can use the menu feature in the newer WordPress. First you want to activate the fact that you want to use this feature via your functions.php file. // This theme uses wp_nav_menu() in two locations. register_nav_menus( array( ‘primary’ => __( ‘Primary Navigation’, ‘your_theme_name’ ), ‘secondary’ => __(‘Secondary Navigation’, ‘your_theme_name’) ) … Read more

Navigation link to specific user page

While you could possibly add a filter to walker_nav_menu_start_el and have your callback function alter/recreate the menu item according to your needs, I would say the best and easiest solution is to implement you own menu walker, and supply that to wp_nav_menu. This should help get you started: class WPSE_90204_Walker extends Walker_Nav_Menu { function start_el( … Read more

Different Main Navigation per category

You could set this in your theme using conditionals. Create a separate menu for each category using the WordPress menu feature (Appearances > Menus). Then in your theme, where you want the menu to display, determine which menu to display using the is_category(‘category-slug’) and/or in_category(‘category-slug’) conditionals and the wp_nav_menu function (http://codex.wordpress.org/Function_Reference/wp_nav_menu). For instance: <?php if(is_category(‘first-category’) … Read more

Full-Ajax Theme: parseJSON error while building a JSON object from a WordPress custom template

Replacing all the specific the_content() functions, or the_ID… etc by the getters equivalent seems to fix the problem. Here the solution: <?php $o = array(); $o[ ‘title’ ] = wp_title( ‘|’, false, ‘right’ ); $o[ ‘type’ ] = ‘single-project’; //ob_start(); $article=”<div id=”container” class=”content-area project-content”>”; $article .= ‘<main id=”main” class=”site-main” role=”main”>’; while (have_posts()) : the_post(); $article … Read more

Replace menu tag with tag

It looks like the above can be achieved with the walker_nav_menu_start_el filter (see reference). <?php function edit_menu_item($item_output, $item) { if ( get_field( ‘dropdown’, $item) == ‘yes’ ) { return ‘<button>’.$item->title.'</button>’; } return $item_output; } add_filter(‘walker_nav_menu_start_el’,’edit_menu_item’, 10, 2); Credit goes to @s_ha_dum via this answer.

Break apart wp_list_pages in order to customise it

This is one of those question where solid answer is not an easy one to follow. This function is powered by Walker_Page class and you can replace it with your own walker (extended from Walker_Page or just Walker) by passing its name in walker argument to wp_list_pages(). In a nutshell it is very highly flexible … Read more

Bar separated navigation by extending Walker_Page

This is what I went with in the end. Although it only will work correctly if you are using a depth of one: class Bar_List_Walker_Page extends Walker_Page { public $count; public $running_count; function __construct() { $this->count = 0; $this->running_count = 0; } function start_el(&$output, $page, $depth, $args, $current_page) { global $post; extract($args, EXTR_SKIP); $css_class = … Read more

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