Develop a plugin to make all images seo friendly to alt tag.

Developerking
2 min readJan 17, 2023

To make images SEO friendly, you can create a plugin that does the following:

  1. Automatically adds alt tags to images that do not have them. The alt tag should accurately describe the image and include relevant keywords.
  2. Optimizes image file sizes to reduce page load times.
  3. Ensures that images are properly tagged with the relevant metadata, such as title and caption.
  4. Provides the option for users to add a brief description of the image via a caption

Please note that to create a plugin you should have some experience with programming, specifically in PHP and WordPress plugin development.

Here’s an example of a simple WordPress plugin that adds alt tags to images that don’t have them:

<?php
/**
* Plugin Name: SEO Friendly Images
* Plugin URI: https://example.com/seo-friendly-images
* Description: This plugin automatically adds alt tags to images that don't have them.
* Version: 1.0
* Author: Mayur Khuman
* Author URI: https://example.com
* License: GPL2
*/


function seo_friendly_images_update_alt_tags() {
global $wpdb;
$images = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%' AND post_excerpt = ''");
foreach ($images as $image) {
$attachment_id = $image->ID;
$attachment = get_post($attachment_id);
$alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
if (empty($alt)) {
$alt = $attachment->post_title;
update_post_meta($attachment_id, '_wp_attachment_image_alt', $alt);
}
}
}
add_action('admin_init', 'seo_friendly_images_update_alt_tags');

This plugin will add alt tags to images that don’t have them. The alt tag will be the same as the image title.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Developerking
Developerking

Written by Developerking

We are creating the world's largest community of developers & Share knowledgeable contents , So Stay Tuned & Connect with us !! Become a Dev King Member.

No responses yet

Write a response