• Resolved yorgosgk

    (@yorgosgk)


    The plugin is working great….posts with no featured images are showing.

    However small images are also coming up on my main nav bar. I have a basic plugin that lets you use images in your nav so i think this is competing. Can we exclude EVERYTHING but the post image? Thanks in advance for the support! Great plugin, just needs a little TLC here.

    See screenshot https://prnt.sc/v3v19e

    • This topic was modified 3 years, 6 months ago by yorgosgk.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author janw.oostendorp

    (@janwoostendorp)

    Hi yorgosgk

    That’s unfortunate to hear. You have a theme which support featured images. How rare. The fix is easy enough:

    Create a file wp-content/plugins/dfi-exclude-nav.php

    and put the following code inside:

    <?php
    /**
     * Plugin Name:       Default Featured Image, exclude navigation items.
     * Plugin URI:        https://wordpress.org/support/topic/default-image-also-showing-on-my-nav-bar/
     * Version:           1.0
     */
    
    function dfi_exclude_nav ( $dfi_id, $post_id ) {
    	$post = get_post($post_id);
    	if ( 'nav_menu_item' === $post->post_type ) {
    		return 0; // Don't use DFI for this posttype
    	}
    	return $dfi_id; // the original featured image id
    }
    add_filter( 'dfi_thumbnail_id', 'dfi_exclude_nav', 10, 2 );
    

    And activate this plugin in WordPress.

    Let me know how it goes

    Jan-Willem

    Thread Starter yorgosgk

    (@yorgosgk)

    Wow, that was unbelievable response time THANKS A LOT! UNFORTUNATALY though 🙁

    Didn’t work!

    https://prnt.sc/v3vi3x

    http://prntscr.com/v3vgxk

    they are still there….

    this is in my php file exactly that i uploaded http://prntscr.com/v3vina

    For what its worth – here is the inspector https://prnt.sc/v3vjok

    Plugin Author janw.oostendorp

    (@janwoostendorp)

    Sorry, I posted the wrong code. (of another question)
    I’ve updated the code in the post above.
    Can you try it?

    Jan-Willem

    Thread Starter yorgosgk

    (@yorgosgk)

    WORKED!

    Really quick question now, if I wanted a default image that’s category specific does this code affect the code you have in the support documentation and in other threads here.?

    Plugin Author janw.oostendorp

    (@janwoostendorp)

    Sorry I didn’t see your reply.

    You can combine and mix them. But some might screw with others.
    It probably should work if you give them the correct order.

    But making 1 filter that handles all would probably be nicer.
    implementing a category check would be:

    
    <?php
    /**
     * Plugin Name:       Default Featured Image, exclude navigation items.
     * Plugin URI:        https://wordpress.org/support/topic/default-image-also-showing-on-my-nav-bar/
     * Version:           1.0
     */
    
    function dfi_exclude_nav( $dfi_id, $post_id ) {
    	$post = get_post( $post_id );
    	if ( 'nav_menu_item' === $post->post_type ) {
    		return 0; // Don't use DFI for this posttype
    	}
    
    	// all which have 'animals' as a category
    	if ( has_category( 'animals', $post_id ) ) {
    
    		//sub category
    		if ( has_category( 'cats', $post_id ) ) {
    			return 7; // cats img
    		} else if ( has_category( 'dogs', $post_id ) ) {
    			return 8; // dogs img
    		}
    
    		return 6; // default animals picture
    	}
    
    	return $dfi_id; // the original featured image id
    }
    
    add_filter( 'dfi_thumbnail_id', 'dfi_exclude_nav', 10, 2 );

    Let me know how it goes

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Default image also showing on my nav bar’ is closed to new replies.