The WordPress wp_list_pages() menus are really easy to customize.
Sometime developer want to add another link or to redirect a link to another page or URL from one of the pages.
For example I have a website http://www.navayan.com and having wp_list_pages() with Home, About, Blog pages. Default that link will open page.php page with respective page that user clicked on. But I want user to be redirect to my wordpress blog ie. https://amolnw.wordpress.com by clicking on ‘Blog’ link.
How will I do that?
By default wordpress takes the Permalink for redirecting a page or post. And to get our own redirection we need to customize one wordpress function call ‘start_el()‘. ‘start_el()’ function does exist in ‘/site_directory/wp-includes/classes.php’ on line number 1168 (line number may change if additional code is there).
Get the page id first
$page_menu_id = 'menu_'.$page->ID;
Then check which page id(s) you want to filter
$pgURL = ''; if ( $page -> ID == '14' ) { #Disabling the active link $pgURL = 'javascript:;'; #Redirecting blog page link to my wordpress blog $pgURL = 'http://amolnw.wordpress.com'; } else { $pgURL = get_page_link( $page -> ID ); } $output .= $indent . '<li>'; $output .= '<a id="'. $page_menu_id .'" href="' . $pgURL . '" title="' . esc_attr(apply_filters('the_title', $page->post_title)) . '">'; $output .= $link_before . apply_filters('the_title', $page->post_title) . $link_after; $output .= '</a>';
Leave a Reply