Need Help about some Coding Issues

I want to show thumbnail with custom size.So, I mean scale the thumbnails to avoid load heavy size to browser.I couldnt do it.

Here is my code in my plugin:

<img class="img-responsive img-whp" style="width: 368px;" src="<?php the_post_thumbnail_url(array(450, 450, true)); ?>" alt="1.jpg">


here is the thumbnail size in my theme function.php:

// Add Thumbnail Theme Support
add_theme_support(‘post-thumbnails’);
add_image_size( ‘team-slider-thumbnail’, 450, 450, true);


How can I do it?

the_post_thumbnail_url( 'team-slider-thumbnail' );

More info:


the_post_thumbnail_url won’t work outside of Loop.

You need this outside of Loop

And this if it is not a post thumbnail, this will work for any image uploaded to Media library

In addition: you should not hard code image dimensions. You shouldn’t use inline CSS at all, with the exception of some dynamic data.

alt=“1.jpg”

I hope this is just some temporary code, because you obviously can’t hardcode ALT attribute for a dynamic image.

I cant show tumbnails with I wanted sizes.For example, in loop, when I add the below code with 100x100 size, the thumbnail shown 100x100.However, when I add 100x300,true, thumbnail size doesnt change.It shown real media size.What is the problem?

   <?php the_post_thumbnail( array(100, 100) ); ?>
                    <?php the_post_thumbnail(array(100, 300, true) ); ?>

First, you shouldn’t use dimensions, you should use size handles (e.g. “team-slider-thumbnail” or whatever you are using).

Second, make sure your images (with corresponding handles) actually physically have the correct dimensions you need. Changing / adding the handles or changing dimension under Settings / Media Settings require you to regenerate your images (there are 3rd party plugins for that)

Third, and most important, man, just learn to use Google. Seriously. If I had to ask about every issue I stumbled upon during my WP theme development on a forum, I would still be developing it with no end in sight. I guarantee you that you will find EVERY answer you need when developing a WP theme online. If you can’t find an answer, then you are simply asking a wrong question.
You are not developing some breakthrough plugin none has ever done. You are dealing with basic WP stuff which I am 100% sure you will figure out if you put some effort and just use google. Figuring the stuff out on your own is the part of being a developer and it is how you grow and actually become a good developer.

Thanks you for your interest about help me.Actually, I made the main structure of theme and related plugins.I need fix some issues about them to match themeforest requipments such as escaping, thumbnail sizes control with wordpress settings before submit it.I searched it google but I couldnt my answer.I dont use 3td party plugins in my theme because when I use them, my theme will be under effect of the plugins.May my customers will wait for fixing of problems sourced 3.party plugins.

Yes, May It is simple problem but when dont know, it is serious problem.So, please help me, how can I show my custom size dimensions on wordpress media settings page? There are some default size such as small,large etc.Must I use only them to give option my customers to change size also match themeforest standartds, or can I show my custom size on that page? How can I doit? I searched, but I couldnt find.You are real author in themeforest so If you dont know the solution, I am sure nobody dont know in google.

The question is, do you really need any additional media sizes in addition to the default ones? I understand some projects may need more than those default four (thumb, medium, large, full), but usually it is just a display of inexperience. For example I have 5 WP themes on ThemeForest and none of them is using custom sizes. I stick just to default ones. And in this case, you shouldn’t programatically change their dimension at all. You just add to your theme documentation chapter about how your users should change them manually if needed.

The fact that you do not want to rely on 3rd party plugins is great, this is my philosophy as well when it comes to WP development, but you actually need skills to back this up.

I already shared with you all the functions you need to display any image in any size you want in my first reply.

You are real author in themeforest so If you dont know the solution, I am sure nobody dont know in google.

Thanks for flattery, but I am not the most knowledgeable WP person. There are MANY people who know much much more about WP development than I do.
Again, if you can’t find answers on google then you are asking wrong questions. Maybe the way you are trying to do it (anything, not just this particularly thing) is fundamentally wrong and you should rethink it from the ground.

And if you really can’t go without having the help from community then at least use some appropriate channels like https://stackoverflow.com for example.
There are much more skilled community and it is actually the right place to get help on stuff like this.

1 Like