WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

is it possible to show the latest posts only in a specific menu?

This is my menu:

'primary' => __('Primary Navigation', 'gonzo'),
'mobile' => __('Mobile Navigation', 'gonzo'),
'copyright' => __('Footer Copyright Menu', 'gonzo'),
'toplevel' => __('Top Secondary Menu', 'gonzo')

modifying this code

I want to show it only in "primary" menu. Thanks ;)

share|improve this question
Do you mean the default listing of posts which you see on the home page? – Chittaranjan Jan 2 '14 at 18:54
Hi, I need to show the latest post of a specific category in a specific menu. – Francesco Craparo Jan 2 '14 at 19:11
I am not sure if I understood this correctly. You can add a menu item to any of the menu you like and select a category from the categories list on the left for that specific menu item. After saving the menu, you can check on the site and that menu link will show the latest posts for that specific category. – Chittaranjan Jan 2 '14 at 19:35
i have a category (id = 46) when i write posts on this category i would like to show the last 5 posts into the menu of header (i have 4 menus and i want to show those only in the "primary" menu). Look at [link]wordpress.stackexchange.com/questions/56250/… – Francesco Craparo Jan 2 '14 at 20:14
up vote 1 down vote accepted

Yes, this is possible:

function latest_posts_menu($items, $args) {
//To a Specific Menu
if ($args->theme_location == 'primary') {

    // Parent Menu Item
    $items .= '<li id="menu-item" class="menu-item">
                <a href="#">' . __('Latest Posts', 'textdomain') . '</a>
                    <ul class="sub-menu">';
    // Create Sub Menus
    foreach ( get_posts(
                    'post_type' => array('post')
            ) as $post ) {
            // Menu Thumbnail. You can change the dimenssion as well as the image class
            $thumb = get_the_post_thumbnail( $post->ID, array(24,24), array("class" => "menu-thumb") );
        $items .= '<li class="sub-menu-item">
                        <a href="'.get_permalink( $post->ID ).'">'. $post->post_title .'</a>
    // Close The Menu
    $items .= '</ul></li>';
    return $items;
add_filter( 'wp_nav_menu_items', 'latest_posts_menu', 10, 2 );

Source: Display Latest Posts In Menu Item

share|improve this answer
Thanks, can I also show the related thumbinal? – Francesco Craparo Jan 4 '14 at 10:54
This code is good but it is not working fine with UberMenu because it not show the thumbnail and it needs to modified the classes manually. – Francesco Craparo Jan 4 '14 at 11:55
Of course you can show related thumbnail. Just add the thumbnail as featured image. Code corrected to display the featured image before submenu. – Abhik Jan 4 '14 at 12:23
Hi,Thanks but I have a trouble with the resize image, it show always the thumbnail 150x150 and not 24x24. – Francesco Craparo Jan 4 '14 at 13:22
Put this on functions.php add_image_size('menuthumbs' 24, 24, true);. Then replace the dimension array (array(24,24))with the thumbnail ID (i.e 'menuthumbs') in get_the_post_thumbnail function. All you need to do after that is rebuild the thumbnail using a plugin. – Abhik Jan 4 '14 at 15:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.