techinfoBiT
  • News
  • Startups
  • Tech
    • Internet
    • Security
  • WebMaster
    • All
    • GEO
    • SEO
    • Server & Hosting
    • Tools
    • WordPress
    'Sorry, This File Type Is Not Permitted for Security Reasons' How To Fix This Error in WordPress Website Development-techinfoBiT

    ‘Sorry, This File Type Is Not Permitted for Security Reasons’ How To Fix This Error in WordPress

    What is DMARC Record in DNS and Why It is Important For Email Security-techinfoBiT

    What is DMARC Record in DNS and Why It is Important For Email Security?

    How To Generate SHA-256 Hash From the Command Line on Ubuntu Server - techinfoBiT-SHA-256,Ubuntu Server, Server Solution, Linux Hashing, File Integrity, Cryptographic Hash, sha256sum, Hash Generation

    How To Generate SHA-256 Hash From the Command Line on Ubuntu Server

    Cloudflare To Deprecate Auto Minify Feature On August 5, 2024 - techinfoBiT

    Cloudflare To Deprecate Auto Minify Feature On August 5, 2024

    What is Google Analytics 4 and How to Setup GA4 for Websites - techinfoBiT

    What is Google Analytics 4 and How to Setup GA4 for Websites?

    How To Use Multiple SPF Records In A Domain | Merge Multiple SPF Easily - techinfoBiT

    How To Use Multiple SPF Records In A Domain | Merge Multiple SPF Easily

  • Science Space
  • Gadgets
    • Laptop & PCs
    • Mobile Phones
    • Wearables
  • More
    • How-To Guides
    • Reviews
    • Telecom
    • Applications
    • Press Release
No Result
View All Result
Services
techinfoBiT
  • News
  • Startups
  • Tech
    • Internet
    • Security
  • WebMaster
    • All
    • GEO
    • SEO
    • Server & Hosting
    • Tools
    • WordPress
    'Sorry, This File Type Is Not Permitted for Security Reasons' How To Fix This Error in WordPress Website Development-techinfoBiT

    ‘Sorry, This File Type Is Not Permitted for Security Reasons’ How To Fix This Error in WordPress

    What is DMARC Record in DNS and Why It is Important For Email Security-techinfoBiT

    What is DMARC Record in DNS and Why It is Important For Email Security?

    How To Generate SHA-256 Hash From the Command Line on Ubuntu Server - techinfoBiT-SHA-256,Ubuntu Server, Server Solution, Linux Hashing, File Integrity, Cryptographic Hash, sha256sum, Hash Generation

    How To Generate SHA-256 Hash From the Command Line on Ubuntu Server

    Cloudflare To Deprecate Auto Minify Feature On August 5, 2024 - techinfoBiT

    Cloudflare To Deprecate Auto Minify Feature On August 5, 2024

    What is Google Analytics 4 and How to Setup GA4 for Websites - techinfoBiT

    What is Google Analytics 4 and How to Setup GA4 for Websites?

    How To Use Multiple SPF Records In A Domain | Merge Multiple SPF Easily - techinfoBiT

    How To Use Multiple SPF Records In A Domain | Merge Multiple SPF Easily

  • Science Space
  • Gadgets
    • Laptop & PCs
    • Mobile Phones
    • Wearables
  • More
    • How-To Guides
    • Reviews
    • Telecom
    • Applications
    • Press Release
No Result
View All Result
techinfoBiT

Display the First Image in Post as Thumbnail for WordPress Posts

Nishant Kumar by Nishant Kumar
December 28, 2018
Reading Time: 2 mins read
Share on FacebookShare on Twitter > XShare via WhatsAppShare on LinkedIn

We have already published an article about WordPress thumbnail image with the title “How To Add Thumbnails to WordPress Posts | Enable Featured Image“. In this post, I am going explain a hook that will make the setting thumbnail image even easier.

So, let’s create a function that detects and returns the first image in the post:

You might also like

How to Install Let's Encrypt SSL on Ubuntu 24.04 VPS, Free HTTPS for All Website - techinfoBiT

How to Install Let’s Encrypt SSL on Ubuntu 24.04 VPS, Free HTTPS for All Websites

June 3, 2026
How to Deploy a Spring Boot Application with PostgreSQL on Ubuntu 24.04 VPS-techinfoBiT

How to Deploy a Spring Boot Application with PostgreSQL on Ubuntu 24.04 VPS

June 2, 2026
function catch_that_image() {   global $post, $posts;   $first_img = '';   ob_start();   ob_end_clean();   $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);   if(count($matches [1]))$first_img = $matches [1] [0];   return $first_img; }

Now let’s use the Timthumb script to insert the image in the post:

<?php function my_first_image($width,$height) { $thumb = catch_that_image(); if ($thumb) : ?> <img src="<?php echo bloginfo('template_url'); ?>/scripts/timthumb.php?src=<?php echo $thumb[0]; ?>&w=<?php echo $width; ?>&h=<?php echo $height; ?>&zc=1&q=100" alt="<?php the_title(); ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" border="0" /> <?php endif; ?> }

Call this function wherever you want to display the thumbnail. I have tried this codes but for me, it did not work when I was adding the caption to the images so you may consider avoiding the caption for the images.

Via: WPRecipes

Tags: Apps/WebAppsFirst Image As ThumbnailHow ToInternetPost as ThumbnailTop Tech BlogWordPress CodexWordPress HooksWordPress TipsWordPress Tutorials
ShareTweetSendShare
Previous Post

Some Free Tools to Manage Your Files on Windows

Next Post

How to Automatically Upload Android Screenshots to The Internet

Nishant Kumar

Nishant Kumar

Nishant is a passionate tech blogger and has been writing about technology since 2007. His insatiable love for gadgets has made him closely follow the advancements & innovations our society has made in terms of technology since a long while now. Nishant is a highly sought after reviewer with many manufacturers requesting his opinions about their products. He covers Mobile Phones, Gadgets, Tools and all kind of tech products to give consumers Genuine Reviews, Buying Guides and reliable news.

Related Articles

How to Install Let's Encrypt SSL on Ubuntu 24.04 VPS, Free HTTPS for All Website - techinfoBiT

How to Install Let’s Encrypt SSL on Ubuntu 24.04 VPS, Free HTTPS for All Websites

by Nishant Kumar
June 3, 2026
0

One of the final and most important steps when launching a website or web application is enabling HTTPS. Whether you're hosting a WordPress website, a Spring Boot application, a Laravel...

How to Deploy a Spring Boot Application with PostgreSQL on Ubuntu 24.04 VPS-techinfoBiT

How to Deploy a Spring Boot Application with PostgreSQL on Ubuntu 24.04 VPS

by Nishant Kumar
June 2, 2026
0

Deploying a Spring Boot application on a VPS involves more than simply uploading application files to a server. A production deployment typically includes a Java runtime, a PostgreSQL database, a...

how to type in Hindi 2026, Hindi typing Windows 11, Google Input Tools alternative, type in Indian languages, Hindi phonetic keyboard Windows, Microsoft Indic Language Input Tool, Gboard Hindi typing-techinfoBiT

How to Type in Hindi and Indian Languages on Any Device in 2026

by techinfoBiT
May 31, 2026
0

If you have been searching for the Google IME offline installer lately, you already know the bad news. Google quietly discontinued the Windows installer years ago. The download links are...

Ubuntu Server How To Find Largest File In Directory Recursively - techinfoBiT

Ubuntu Server: How To Find Largest File In Directory Recursively

by Nishant Kumar
March 24, 2025
0

When managing an Ubuntu Server, disk space can quickly become an issue, especially if large files accumulate unnoticed. If you need to identify the biggest file within a directory (including...

Load More
Next Post
How to Automatically Upload Android Screenshots to The Internet - techinfoBiT

How to Automatically Upload Android Screenshots to The Internet

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.

techinfoBiT | Startup & Tech News, Reviews | WebMaster, How-To Guides-Tech Blog-Startup Blog India

techinfoBiT is your go-to source for the latest startup & tech news, technology reviews; WebMaster, SEO tips and how-to guides to help you stay updated and navigate the digital world know more

  • About
  • Contacts
  • Disclaimer
  • Privacy Policy

© 2012-2025 techinfoBiT | All Rights Reserved

No Result
View All Result
  • News
  • Startups
  • Tech
  • WebMaster
  • Gadgets
  • How-To Guides
  • Science Space
  • Services

© 2012-2025 techinfoBiT | All Rights Reserved