• Hello – I’ve looked for the answer and admit to being a bit stumped. In the release notes 4 months ago, this was announced:

    An new pluggable function ( hu_print_placeholder_thumb() ) has been introduced in the following templates :
    – content-featured.php
    – content.php
    – parts/related-posts.php
    This function can be overridden to display your own custom placeholder thumbnail.

    May I humbly ask how to override the functions? I’ve copied the three files to my child-theme folder, created a folder called “img” with my new thumb-standard, thumb-small and thumb-medium files. But now I’m stumped.

    Many thanks!

Viewing 13 replies - 1 through 13 (of 13 total)
  • Hi bowoolley. Welcome to the Hueman forum. You don’t need the three php files in your child theme. The hu_print_placeholder_thumb() uses a filter to set the placeholder source. You can use the same filter in your child theme functions.php file. This should work:

    // use custom image placeholder
    add_filter( 'hu_placeholder_thumb_src' , 'my_image_placeholder');
    function my_image_placeholder($src) {
      $src= 'url-to-your-placeholder-image-file';
      return $src;
    }

    You could use an image in your Media Library or an image outside of WP.

    Thread Starter bowoolley

    (@bowoolley)

    Hi – thanks for the welcome!

    Well, I’ve tried the code in my child theme’s functions.php, and refreshed browsers, checked the link… I know I’m missing something. Here’s the code:

    <?php
    //do not remove this
    load_template( get_template_directory() . '/functions/init-core.php' );
    
    /* Write your awesome functions below */
    
    // use custom image placeholder
    add_filter( 'hu_placeholder_thumb_src' , 'my_image_placeholder');
    function my_image_placeholder($src) {
      $src= 'https://www.mydomain.com/wp-content/themes/mychildtheme/img/thumb-medium.png';
      return $src;
    }

    I’ve changed the names of domain and theme to protect the innocent… ??

    Thread Starter bowoolley

    (@bowoolley)

    Follow-up: The code did indeed work. Typical newbie error (and I’ve been making WordPress sites since 2008) – I hadn’t activated the child theme. Sorry.

    New issue: the custom image shows for “medium” thumbs (that’s the image I directed the url to), but not widget or small. I’m not sure what to change / add.

    Thanks for your help!

    First thing I’d try is changing the image name. “thumb-medium” is the name used by the theme in various places. I don’t know if this might cause a conflict but, when I ran a test with a unique image name, it replaced the default placeholder in all three locations that use the hook. If the custom image is being displayed, but it’s out of proportion, then it needs to be the same aspect ratio as the “thumb-medium” which is 2.122/1 (520×245).

    Thread Starter bowoolley

    (@bowoolley)

    Well, I tried that – duplicated thumb-medium, renamed it “placeholder”, changed the code. I also did a regenerate thumbnails. The medium size shows up fine, the other two are still referring to the file in the Hueman folder instead of to the child theme…

    You removed these from your child theme?
    – content-featured.php
    – content.php
    – parts/related-posts.php

    Thread Starter bowoolley

    (@bowoolley)

    I did indeed.

    The medium size shows up fine, the other two are still referring to the file in the Hueman folder instead of to the child theme…

    Can you post a link to your site? Where is it you’re seeing the “medium size”? And where is it that the “other two” aren’t showing up? If they aren’t showing up then you’re seeing the default theme placeholder instead?

    Thread Starter bowoolley

    (@bowoolley)

    I can’t actually post a link to the site, since it’s a closed community… But I’ll try to explain better.

    The above code is in functions.php in my child theme (but I changed “thumb-medium” to “placeholder”.)
    The placeholder image is in the child theme, in a folder called “img”.
    There are no other images or files in the child theme (except style.css).

    The “You may also like” section uses thumb-medium. The new placeholder image, which is in the child theme, shows up fine:

    ….com/wp-content/themes/-mychildtheme-/img/placeholder.png

    The widgets use thumb-small. The image source still shows:

    ….com/wp-content/themes/hueman/assets/front/img/thumb-small.png

    The category page uses thumb-standard. The image source is:

    ….com/wp-content/themes/hueman/assets/front/img/thumb-standard.png

    So for some reason, the only size that’s being affected is thumb-medium.

    Thread Starter bowoolley

    (@bowoolley)

    Here’s the exact content of the child theme’s functions.php (with domain name changed):

    <?php
    //do not remove this
    load_template( get_template_directory() . '/functions/init-core.php' );
    
    /* Write your awesome functions below */
    
    // use custom image placeholder
    add_filter( 'hu_placeholder_thumb_src' , 'my_image_placeholder');
    function my_image_placeholder($src) {
      $src= 'https://www.-domain-.com/wp-content/themes/-childtheme-/img/placeholder.png';
      return $src;
    }

    Thanks for the explanation; that helps. The issue is that the hook is only used in those locations that display the “thumb-medium” size of 520×245. In your home and archive pages, if you have the “standard” post layout of a single column, that uses the “thumb-standard” image which is 320×320. We can modify the content-standard template to use your custom image but it will be a scaled-down rectangle instead of a square. For the widgets, your custom image should show up in the Hueman Posts widget but it won’t be in the Hueman Dynamic Tabs widget. The tabs widget uses the “thumb-small” which is 160×160. If we modify that widget template, your custom image would again be a scaled-down rectangle. In both of these instances the modifications would work; the images just wouldn’t all be the same size.

    Thread Starter bowoolley

    (@bowoolley)

    It sounds like the easiest thing to do is replace the default images in the main folder, and just upload them again with each update… ??

    That’s certainly an option. You just need to remember that when you update the theme.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Use my own placeholder image’ is closed to new replies.