Site Health

Google’s advice on alt text for images focuses on accessibility, SEO, and user experience. Properly using alt attributes helps search engines understand the content of your images, improves your website’s visibility in image search, and makes your site accessible to visually impaired users who rely on screen readers.

Google’s Best Practices for Alt Text

  1. Use Descriptive, Relevant Alt Text
    • The alt attribute should describe the image’s content accurately and succinctly.
    • Be specific and contextual—describe the image in relation to the surrounding content.
    • Avoid overly generic descriptions like “image,” “photo,” or “graphic.”
    Example:
    Instead of: <img src="dog.jpg" alt="dog">
    Use: <img src="dog.jpg" alt="Golden Retriever playing in the park">

  1. Incorporate Keywords Naturally
    • Include keywords relevant to the page’s content, but avoid keyword stuffing.
    • Make sure the keywords fit naturally into the description rather than sounding forced.
    Example:
    If your page is about SEO tools, a relevant alt text could be:

  1. Keep Alt Text Concise
    • Google suggests keeping alt text brief yet descriptive, ideally under 125 characters.
    • Screen readers often cut off descriptions after 125 characters, so be mindful of length.

  1. Avoid Keyword Stuffing and Redundancy
    • Keyword stuffing can harm your SEO and make descriptions unreadable.
    • Don’t use phrases like “image of” or “photo of”—screen readers already announce that it’s an image.
    Example of what NOT to do:

  1. Decorative Images
    • If an image is purely decorative and provides no useful information, use a blank alt attribute (alt="").
    • This allows screen readers to skip the image, improving accessibility.
    Example:
    <img src="decorative-line.jpg" alt="">

  1. Use Alt Text for Image Links
    • When images are used as links, the alt text should describe the link’s destination, not just the image itself.
    Example:

  1. Avoid Using File Names as Alt Text
    • Google advises against using image file names as alt text.
    • Always provide a proper description instead of something like: alt="img1234.jpg".

📌 Why This Matters for SEO and Accessibility

  • SEO: Proper alt text can improve your visibility in Google Image Search and improve the context of your entire page.
  • Accessibility: It ensures that all users, including those using screen readers, can understand the content and purpose of images.

💡 Google’s Own Advice Sources

How to Check Your Image Alt Text

Here’s a step-by-step guide to analyze your site’s images and generate optimized alt text automatically. We’ll create a WordPress plugin that scans your posts and pages, checks for images without alt text, and suggests optimized descriptions based on surrounding content.


📌 Steps to Create the Plugin

1. Create the Plugin Folder and File

  • In your WordPress installation, go to /wp-content/plugins/
  • Create a folder called alt-text-optimizer
  • Inside this folder, create a PHP file named alt-text-optimizer.PHP

2. Add Basic Plugin Code

Add this code to alt-text-optimizer.PHP:


3. Upload and Activate the Plugin

  • Upload the alt-text-optimizer folder to your WordPress plugins directory.
  • Go to your WordPress dashboard, then Plugins > Installed Plugins.
  • Activate the Alt Text Optimizer.

4. Test the Plugin

  • Go to Tools > Alt Text Optimizer in your WordPress admin menu.
  • The plugin will scan your posts and pages, showing a list of images missing alt text.

5. Adding Alt Text Suggestions (AI-Powered)

Let’s enhance the plugin to suggest alt text based on surrounding content.

Add this code below the previous one in alt-text-optimizer.PHP:

function generate_alt_text($image_tag, $content) {
    $context = wp_strip_all_tags($content);
    $context = mb_substr($context, 0, 500); // Limit to 500 characters of context
    $alt_text = "Image related to: " . $context;
    return $alt_text;
}

Now, modify the plugin’s admin page function like this:

foreach ($posts as $post) {
    preg_match_all('/<img [^>]*>/i', $post->post_content, $matches);

    foreach ($matches[0] as $img_tag) {
        $total_images++;
        if (!preg_match('/alt="[^"]*"/i', $img_tag)) {
            $images_without_alt++;
            $suggested_alt = generate_alt_text($img_tag, $post->post_content);
            echo '<div>';
            echo '<pre>' . htmlentities($img_tag) . '</pre>';
            echo '<p>Suggested Alt Text: <strong>' . htmlentities($suggested_alt) . '</strong></p>';
            echo '</div><hr>';
        }
    }
}

6. How This Works

  • The plugin scans all published posts and pages.
  • It detects images without alt text and displays them.
  • It generates alt text suggestions based on the content surrounding each image.
  • It suggests alt text like: Image related to: (short description of the content).

7. Improving the Plugin (Optional)

Would you like me to help you:

  • Add a button to automatically update the alt text in the database?
  • Integrate AI (like GPT-4) for even better descriptions?
  • Include bulk processing and SEO reporting features?

Making a WordPress Plug-in for Image Alt Checking

Absolutely! Let’s build a full WordPress plugin that:

  • Scans your entire site for images missing alt text.
  • Generates AI-powered alt text suggestions based on surrounding content.
  • Automatically updates missing alt attributes in the database if you choose to apply them.

📌 WordPress Plugin: Alt Text Optimizer

🔨 Step 1: Create Plugin Folder and File

  1. Go to your WordPress plugins directory: /wp-content/plugins/
  2. Create a folder called alt-text-optimizer.
  3. Inside that folder, create a file named alt-text-optimizer.PHP.

🔨 Step 2: Add the Plugin Code

Paste the following code into alt-text-optimizer.PHP:


🔨 Step 3: Install and Activate Plugin

  1. Upload the alt-text-optimizer folder to /wp-content/plugins/.
  2. Go to WordPress Dashboard > Plugins > Installed Plugins.
  3. Activate the Alt Text Optimizer.

🔨 Step 4: Use the Plugin

  1. Navigate to Dashboard > Alt Text Optimizer.
  2. The plugin will scan all posts and pages, displaying images missing alt text.
  3. Suggested alt text will be generated based on the content surrounding each image.
  4. Click the “Apply Alt Text” button to save the alt text directly into your database.

Features Added

  • Scans all posts and pages for missing alt text.
  • Generates alt text suggestions based on surrounding text content.
  • Allows you to apply suggestions with a single click.
  • Automatic database update when applying alt text.

🚀 Future Improvements

Would you like me to help you:

  • Integrate GPT-4 to generate richer, more relevant alt text?
  • Add bulk updating functionality for faster processing?
  • Generate SEO reports for images missing alt text?

Shall we proceed? 😊Absolutely! Let’s build a full WordPress plugin that:

  • Scans your entire site for images missing alt text.
  • Generates AI-powered alt text suggestions based on surrounding content.
  • Automatically updates missing alt attributes in the database if you choose to apply them.

📌 WordPress Plugin: Alt Text Optimizer

🔨 Step 1: Create Plugin Folder and File

  1. Go to your WordPress plugins directory: /wp-content/plugins/
  2. Create a folder called alt-text-optimizer.
  3. Inside that folder, create a file named alt-text-optimizer.PHP.

🔨 Step 2: Add the Plugin Code

Paste the following code into alt-text-optimizer.PHP:


🔨 Step 3: Install and Activate Plugin

  1. Upload the alt-text-optimizer folder to /wp-content/plugins/.
  2. Go to WordPress Dashboard > Plugins > Installed Plugins.
  3. Activate the Alt Text Optimizer.

🔨 Step 4: Use the Plugin

  1. Navigate to Dashboard > Alt Text Optimizer.
  2. The plugin will scan all posts and pages, displaying images missing alt text.
  3. Suggested alt text will be generated based on the content surrounding each image.
  4. Click the “Apply Alt Text” button to save the alt text directly into your database.

Features Added

  • Scans all posts and pages for missing alt text.
  • Generates alt text suggestions based on surrounding text content.
  • Allows you to apply suggestions with a single click.
  • Automatic database update when applying alt text.

🚀 Future Improvements

Then we can also:

  • Integrate GPT-4 to generate richer, more relevant alt text?
  • Add bulk updating functionality for faster processing?
  • Generate SEO reports for images missing alt text?

This will allow you to input your API for ChatGPT and enter a subject for the blog so that all images have a relevant alt text title.