Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8839887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:20:19+00:00 2026-06-14T10:20:19+00:00

Below is a WordPress function that pulls in a thumbnail image for a menu.

  • 0

Below is a WordPress function that pulls in a thumbnail image for a menu. How do I add an if/else to display “No thumbail” if there is no thumbail?

I have tried:

$item_output .= apply_filters( 'menu_item_thumbnail' , ( !isset( $args->thumbnail ) && $args->thumbnail ) ) ? 'no thumbnail' : '';

But this had no effect. Sorry if this is a dumb question, but I don’t know PHP.

The function:

class Menu_With_Description extends Walker_Nav_Menu {
    function start_el(&$output, $item, $depth, $args) {
        global $wp_query;


        // get user defined attributes for thumbnail images
        $attr_defaults = array( 'class' => 'nav_thumb' , 'alt' => esc_attr( $item->attr_title ) , 'title' => esc_attr( $item->attr_title ) );
        $attr = isset( $args->thumbnail_attr ) ? $args->thumbnail_attr : '';
        $attr = wp_parse_args( $attr , $attr_defaults );

        $item_output = $args->before;

        // thumbnail image output
        $item_output .= ( isset( $args->thumbnail_link ) && $args->thumbnail_link ) ? '<a' . $attributes . '>' : '';
        $item_output .= apply_filters( 'menu_item_thumbnail' , ( isset( $args->thumbnail ) && $args->thumbnail ) ? get_the_post_thumbnail( $item->object_id , ( isset( $args->thumbnail_size ) ) ? $args->thumbnail_size : 'thumbnail' , $attr ) : '' , $item , $args , $depth );
        $item_output .= ( isset( $args->thumbnail_link ) && $args->thumbnail_link ) ? '</a>' : '';

        // menu link output
        $item_output .= '<a'. $attributes .'>';
        $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
        $item_output .= '</a>';

        // menu description output based on depth
        $item_output .= ( $args->desc_depth >= $depth ) ? '<br /><span class="sub">' . $item->description . '</span>' : '';

        // close menu link anchor
        $item_output .= $args->after;

        $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
    }
}

This applies the above to my menu:

add_filter( 'wp_nav_menu_args' , 'my_add_menu_descriptions' );
function my_add_menu_descriptions( $args ) {
    if ( $args['theme_location'] == 'my_menu' ) {
         $args['walker'] = new Menu_With_Description;
         $args['desc_depth'] = 0;
         $args['thumbnail'] = true;
         $args['thumbnail_link'] = true;
         $args['thumbnail_size'] = 'homeboxes';
         $args['thumbnail_attr'] = array( 'class' => 'nav_thumb my_thumb' , 'alt' => 'test' , 'title' => 'test' );
        }
    return $args;   
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:20:21+00:00Added an answer on June 14, 2026 at 10:20 am

    Don’t modify the Class. Use this filter instead:

    add_filter( 'menu_item_thumbnail', 'so_13368049_change_thumb', 10, 4 );
    
    function so_13368049_change_thumb( $thumb, $item , $args , $depth )
    {
        if( '' == $thumb )
            return 'No thumbnail';
    
        return $thumb;
    }
    

    And if you were to modify the Class, it should be like this:
    ('NO THUMBNAIL' instead of '')

        $item_output .= apply_filters( 'menu_item_thumbnail' , ( isset( $args->thumbnail ) && $args->thumbnail ) ? get_the_post_thumbnail( $item->object_id , ( isset( $args->thumbnail_size ) ) ? $args->thumbnail_size : 'thumbnail' , $attr ) : 'NO THUMBNAIL' , $item , $args , $depth );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to Display Google Map into my wordpress site. I have used below
I have used the remove_action function in Wordpress before to remove junk from the
The function below acts as an slidetoggle accordion (for a list of Wordpress posts)
im making a wordpress plugin and i have a function where i import images,
Alright here is the thing, I have this site that was once wordpress but
I am using wordpress and I have an SQL statement (as below) to gather
I noticed in Wordpress, for example, that there are multiple if statements with blank
I'm using the function below that toggles divs, and with it, any one of
I'm having difficulty finding which jQuery plugin or something else in Wordpress that is
I'm trying to create a PHP 'if' statement that tells an image to display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.