Welcome Guest! Login? Checkout

Recently I had something that I was stuck on for ages. I was trying to set a WordPress Child Theme thumbnail image size and I just couldn’t do it. It sounds simple, doesn’t it – set_post_thumbnail_size is the function and that’s it, unfortunately when it comes to child themes it isn’t that simple.

Child Themes functions.php

In general, the child theme is loaded after the parent theme. This can cause problems with the functions.php as occasionally you can get functions called exactly the same, but when it comes to set_post_thumbnail_size whatever the last set_post_thumbnail_size is present that becomes the size. So if your parent theme sets it to 100 pixels square but your child theme sets it to 200 pixels square, then the featured image will be 200 pixels square.

The problem can occur if you simply add set_post_thumbnail_size to your functions.php, as this could even load the thumbnail size as 100 pixels, particularly if the call is called from within a hook, or a plugin, so you will need to make sure that the child theme set_post_thumbnail_size is loaded last.

Setting the WordPress Child Theme Thumbnail The Right Way

Of course, there is a way to make sure that the child theme uses your new thumbnail size, and this is using the after_setup_theme action.

This action runs after the theme is setup, so everything is loaded and present on the site and we’re ready to start displaying the theme, to use this hook, simply use the following code to set the thumbnail size (obviously changing 825, 400 & true to your chosen height, width & crop level).

The only thing to possibly add is that you may need to change the number at the end of the action from 100 to something else dependant on if it loads or not, but that is trial and error dependant on the preview theme, but most parent themes would add their actions to the priority of 10 (the higher number is more priority).

 
 
 

Comments

Polite Disclaimer: I am welcome, open and willing for corrections to be shared in the comments (with corrections being added to posts and credited), and the comments field should be used to promote discussion and make this post better. I do not know everything and if anybody finds a better way to do something, then by all means please share it below.

However, I'm unable to offer support to posts. The reason being is that WordPress has tens of thousands of plugins and millions of themes. As such, finding out exactly why code doesn't work with your setup is a long process. If you wish for me to look at your code, please use the priority support area.

Comments asking support will be left on the site, but there is no guarantee of answer.

    Leave a Reply

    Your email address will not be published.

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">
    *