Okay
  Public Ticket #946504
Default thumbnail image
Closed

Comments

  •  2
    sladd56 started the conversation

    How can I set a default thumbnail image for our site? I believe this is the code I need but can't figure out where to add it:

    <?php if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else { ?>
    <img src="<?php bloginfo('template_directory'); ?>wp-content/uploads/Reviews.jpg"
    alt="<?php the_title(); ?>" />
    <?php } ?>


  •  3,030
    Andrew replied

    Hi there,

    Thanks for contacting us regarding your query.

    This can be achieved by the use of Custom CSS Code.

    May I ask you to provide me with the URL(s) of the pages where you would like to have these thumbnails adjusted and also what dimension you would like them to be?

    I look forward to your reply.  

    Cheers! 

  •  2
    sladd56 replied

    Hi Andrew,

    The problem is we are running v7.0.8 due to custom code on our store pages that disappears when we update; hopefully that will be addressed soon. But in the meantime I cannot find an option in this version of the theme to add Custom CSS.

    I would like the thumbnail to be pulled anytime a visitor uses our social sharing buttons at invigor8.com. I understand Facebook will reject images smaller than 200x200 and recommended square image size is 460x460, but I can take care of that myself if I know where to add the code. Thanks!


  •  3,030
    Andrew replied

    Hi there,

    Thanks for contacting us regarding your query.

    Its a bit strange that you are not seeing an option to add Custom CSS through the Salient Theme Options.

    Would you mind if we logged in and investigated this?

    Alternatively, (and maybe its a route you might not want to take since it involves installing another plugin) you could use the Simple Custom CSS plugin and add the  Custom CSS Code code here.

    I look forward to your reply. 

    Cheers! 


  •   sladd56 replied privately
  •  2
    sladd56 replied

    Hi Andrew,

    I actually located the "CSS/Script Related" tab under general settings. Can you guide me on where to add the default thumbnail code? I would like a default image to appear anytime someone shares a page or post on the website that does not include a featured image. I believe the following is the code I would need but not sure where to place it in the custom CSS box:

    <?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } else { ?> <img src="<?php bloginfo('template_directory'); ?>wp-content/uploads/Reviews.jpg" alt="<?php the_title(); ?>" /> <?php } ?>

  •  3,030
    Andrew replied

    Hi Sally,

    Apologies for the bit of confusion from our end. We are guessing you got the code from here http://www.wpbeginner.com/wp-themes/how-to-set-a-default-fallback-image-for-wordpress-post-thumbnails/

    The original code was PHP code and needs to be added to a PHP file like the functions.php file i.e. salient \ functions.php 

    Also, try and use a filter instead of the plain conditional statement i.e. http://wordpress.stackexchange.com/questions/134014/how-do-i-change-modify-the-post-thumbnail-html-output

    The filter would be run everytime the method get_the_post_thumbnail is used on the theme files.
    Hope this is a workable option.

  •  2
    sladd56 replied

    OK, I'll see if I can figure this out, thanks!  But can you provide guidance on where this code should be placed in the functions.php file?

  •  3,030
    Andrew replied

    Hi Sally,

    You could add it after the language set up section i.e. line 10 looks like this

    #-----------------------------------------------------------------#
    # Load text domain
    #-----------------------------------------------------------------#
    add_action('after_setup_theme', 'lang_setup');
    function lang_setup(){
        
        load_theme_textdomain(NECTAR_THEME_NAME, get_template_directory() . '/lang');
        
    }
    

    You can add the filter like this:

    #-----------------------------------------------------------------#
    # Load text domain
    #-----------------------------------------------------------------#
    add_action('after_setup_theme', 'lang_setup');
    function lang_setup(){
        
        load_theme_textdomain(NECTAR_THEME_NAME, get_template_directory() . '/lang');
        
    }
    #-----------------------------------------------------------------#
    # setup default blog image
    #-----------------------------------------------------------------#
    add_filter('after_setup_theme', 'default_image_setup');
    function default_image_setup(){    
        
    }
    

    There is also an article here that can help http://justintadlock.com/archives/2012/07/05/how-to-define-a-default-post-thumbnail

    Hope this clears things up.

  •  2
    sladd56 replied

    OK, will give that a shot. Thanks!

  •  2
    sladd56 replied

    Hello Again,


    I am finally circling back to this. I have added the code as provided to the functions.php file, but where do I specify the default thumbnail image?

    Thanks!

    Sally

  •  3,030
    Andrew replied

    Hi Sally,

    Thanks for your reply,

    You will be required to change the URL of the default code you would like to use to the absolute URL of an image you will upload to the Media section of your WordPress Dashboard.

    so for example, in the code you have provided <img src="<?php bloginfo('template_directory'); ?>wp-content/uploads/Reviews.jpg" you will need to change wp-content/uploads/Reviews.jpg to the new image absolute URL.

    Please let me know if there are any more questions that I may answer for you :)

    Cheers!