Working with Images
Add an Automatic ‘Featured Image’ to Blog Posts Based on Category
Using featured images in post archives is a common feature of themes, but sometimes you might want to use featured images a bit differently. Occasionally I've worked on sites where the images to be displayed relate to the category a post is in and not to the post itself. Instead of adding the same featured image to every post in each category, it would be much simpler if I could just assign the category to each of my images, and then display the featured image for the category with the post. Examples of when you might want to do this...
How to define a default post thumbnail (2 methods)
Two simple ways to correctly define a default post thumbnail (i.e., featured image) in WordPress. I’ve seen a few tutorials floating around the WordPress-o-Sphere about setting a default post thumbnail for WordPress’ featured image functionality. Some involve tactics like saving a permanent default image (theme authors, please don’t do that). A default thumbnail is generally not something that’s permanent, so you wouldn’t want to save it, leaving yourself a world of pain if you ever wanted to change it in the future. I’ll keep this simple and afford you that future flexibility. I’ll even show you two ways to do...
Add Fallback Image as Post Thumbnail Manually
First, you need to create an image that you want to use as the default image. Next, you need to upload it to your theme’s images folder using a FTP client. Your theme’s images folder is located inside /wp-content/themes/yur-theme/ folder. If it doesn’t have the images folder, then you need to create it. After you have uploaded the image to your website, the next step is to tell WordPress to look for this image when a post doesn’t have its own post thumbnail. Your WordPress theme displays post thumbnails in various places. You need to look for the_post_thumbnail() function in theme files. Typically, you’ll find...
Reduce Image Bloat in WordPress And Get Rid Of Unused File
If you use a lot of photos and graphics on your WordPress site, you’ve probably accumulated a tonne of image files on your server that you have no use for. This is a quick and effective strategy for cutting down on excess image files and only keeping what you actually need. The image bloat problem When you upload a photo or graphic to your site, by default WordPress creates four different sizes of the image: Thumbnail, Medium, Large and Full Size. In all likelihood, you’re only going to use one of these image sizes. But you’ve now got four or five separate files...
Image sizes in WordPress
A user asked me a few days ago how to get the image width and height of a custom-defined image size in WordPress. After searching through the WordPress source code, I couldn’t find a function that handled this. I suppose there really aren’t too many uses for it, but this user needed these values for a custom script, which at least intrigued me enough to write out a custom function to handle this. In this tutorial, I’ll walk you through adding custom image sizes as well as getting these image sizes within your custom scripts. This is not a complete...
Setting a Fallback for Post Thumbnails in WordPress
One of the countless things that I love about WordPress is how easy and efficient the process of adding new content is. All you have to do is provide the art and copy and your theme will take care of the rest. While this workflow is usually smooth, there are times the end user can miss a step or two. I've noticed when working on larger sites with multiple authors one of the most common things to slip through the cracks is setting a featured image. While this shouldn't break your theme, it can create layout inconsistencies or (shudder) broken...
How To Require a Featured Image Before You Can Publish a Post
Are you looking for a way to require a featured image before you can publish a post? This snippet will require that you have added a featured image before your post can be published. If you try to publish a post without a featured image after adding this snippet, you will receive this message: “You must select Featured Image. Your Post is saved but it can not be published.” Instructions: All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin: add_action('save_post', 'wpds_check_thumbnail'); add_action('admin_notices', 'wpds_thumbnail_error'); function wpds_check_thumbnail($post_id) { // change...
Slick Slider WordPress Without Plugin | Slick Carousel
In this blog we will learn how to add a slick carousel in a WordPress Theme without using any plugins. There are couple of ways you can add a slick carousel in WordPress: Using slick-carousel npm package, or,Download required slick files. In this blog we will learn the second way, by downloading the slick files. Step One: Download Slick Carousel files: The first thing we need to do is download the slick files from kenwheeler.github.io Create a directories called assets, src and library in the root of your project in the following order. your-theme > assets > src > libraryCreate two more directories inside library called css and js https://imranhsayed.medium.com/slick-slider-wordpress-without-plugin-slick-carousel-ef2394c737ef