• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Default Featured Imaged depending on author

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Default Featured Imaged depending on author

This topic is: resolved

Tagged: default featured image, default thumbnail, fallback image, featured image

  • This topic has 9 replies, 5 voices, and was last updated 10 years, 8 months ago by Brad Dalton.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • October 28, 2014 at 6:00 pm #129650
    SelenaD
    Member

    I need some PHP help - it's not my strong suit. I'm hoping one of you geniuses can help me out!

    I can successfully use this snippet to add a default image:

    add_filter('genesis_get_image', 'default_image_fallback', 10, 2);
    function default_image_fallback() {
    	
    	if(has_post_thumbnail()) {
    		the_post_thumbnail();
    		
    }	else
    		echo '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/sam-thumb.jpg' . '" alt="" />';
    	
    }

    However, I need to have my default image be different depending on who the author is. So I tried this:

    add_filter('genesis_get_image', 'default_image_fallback', 10, 2);
    function default_image_fallback() {
    	$author_id=$post->post_author;
    	
    	if(has_post_thumbnail()) {
    		the_post_thumbnail();
    		
    }	elseif($author_id = "2") {
    		echo '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/jon-thumb.jpg' . '" alt="Jonathan Warner" />';
    
    	
    }	elseif($author_id = "3") {
    		echo '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/sam-thumb.jpg' . '" alt="Samuel Warner" />';		
    }
    }

    However, I get the image for $author_id="2" for both authors. What am I missing?

    Thanks to anyone who can help!

    http://67.225.230.212/~warnerlawyers/blog/
    October 29, 2014 at 3:21 am #129684
    Sridhar Katakam
    Participant

    Try changing the last elseif to else.

    It should be like this:

    if ( condition ) {
        action1();
        action2();
    } elseif ( condition2 && condition3 ) {
        action3();
        action4();
    } else {
        defaultaction();
    }

    Source: http://make.wordpress.org/core/handbook/coding-standards/php/


    Genesis Tutorials | Follow me on Twitter

    October 29, 2014 at 7:12 am #129716
    SelenaD
    Member

    I still only get the the picture of author id = 2.

    I tried this:

    $author_id=the_author_meta('ID');
    
    function default_image_fallback() {	
    	if(has_post_thumbnail()) {
    		the_post_thumbnail();
    		
    }	elseif($author_id = "2") {
    		echo '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/jon-thumb.jpg' . '" alt="Jonathan Warner" />';
    
    	
    }	elseif($author_id = "3") {
    		echo '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/sam-thumb.jpg' . '" alt="Samuel Warner" />';		
    }
    
    	else {
    		echo '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/default-thumb.jpg' . '" alt="Samuel and Jonathan Warner" />';
    }
    	
    }

    I also tried removing the second "elseif" and moving straight to the else statement. That didn't work either - still got the first author's picture each time.

    I tried defining the author id differently just in case that was the problem, but it isn't. I've echoed the $author_id to make sure it's pulling the correct id for each author and it is. 🙁

    October 29, 2014 at 11:28 am #129770
    Brad Dalton
    Participant

    Here's how i would code it http://wpsites.net/web-design/set-fallback-featured-image-default-for-different-authors-in-genesis/


    Tutorials for StudioPress Themes.

    October 30, 2014 at 10:15 am #129894
    SelenaD
    Member

    Thank you Brad - that did the trick!

    November 9, 2014 at 9:35 am #130984
    decarn
    Member

    Hi,

    Can someone help on how I can change the fallback image from authors to categories?

    Thanks

    November 9, 2014 at 11:26 am #130992
    Brad Dalton
    Participant

    Try this http://wpsites.net/web-design/set-fallback-featured-image-for-each-category-in-genesis/


    Tutorials for StudioPress Themes.

    November 9, 2014 at 12:16 pm #130996
    decarn
    Member

    Hi Brad,

    I notice two sets of code. May I know the difference and which is more efficient?

    February 26, 2015 at 5:41 pm #142447
    joycegrace
    Participant

    That code snippet doesn't work for me. I'm baffled as to why. Does anyone know how I can just add a default featured image? Doesn't have to depend on the author or category.


    Find me at Joyce Grace (http://www.joycegrace.ca)

    February 26, 2015 at 8:38 pm #142464
    Brad Dalton
    Participant

    There is another snippet there which only displays a default image for all posts that don't have one rather than for each category.


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 10 posts - 1 through 10 (of 10 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble