Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maxyudin/7178dec98db899f913345f2da22fd595 to your computer and use it in GitHub Desktop.
Save maxyudin/7178dec98db899f913345f2da22fd595 to your computer and use it in GitHub Desktop.
<?php
function wpse267737_add_nav_menu_items($nav_menu_items) {
// get post ID from URL
$post_id = $_GET['post'];
// get current post data
$link_url = get_permalink( $post_id );
$link_anchor = get_the_title( $post_id );
// build new menu item
$new_menu_item = '<li><a href="' . $link_url . '">' . $link_anchor . '</a></li>';
// concatenate existing items and new
$nav_menu_items .= $new_menu_item;
return $nav_menu_items;
}
// change TEST-MENU-SLUG to the relevant menu slug
add_filter( 'wp_nav_menu_TEST-MENU-SLUG_items', 'wpse267737_add_nav_menu_items' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment