Skip to content

Instantly share code, notes, and snippets.

@webzunft
Created June 4, 2025 16:13
Show Gist options
  • Save webzunft/bf6cf0707afa180fea10c89a43f88552 to your computer and use it in GitHub Desktop.
Save webzunft/bf6cf0707afa180fea10c89a43f88552 to your computer and use it in GitHub Desktop.
Reverse Image Search Plugin for WordPress
<?php
/**
* Plugin Name: ISC Reverse Image Search Link
* Plugin URI: https://imagesourcecontrol.com/blog/reverse-image-search-plugin/
* Description: Adds a "Reverse Search" link to the WordPress Media Library list view for images, linking to Google Image Search.
* Version: 1.0.0
* Author: Thomas Maier @ Image Source Control
* Author URI: https://imagesourcecontrol.com/
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: isc-reverse-search
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
// Add a 'Reverse Search' column to the Media Library list view
function isc_add_reverse_search_column_plugin( $columns ) {
$columns['reverse_search'] = __( 'Reverse Search', 'isc-reverse-search' );
return $columns;
}
add_filter( 'manage_media_columns', 'isc_add_reverse_search_column_plugin' );
// Populate the 'Reverse Search' column
function isc_reverse_search_column_content_plugin( $column_name, $post_id ) {
if ( 'reverse_search' !== $column_name ) {
return;
}
// Check if the attachment is an image
if ( wp_attachment_is_image( $post_id ) ) {
$image_url = wp_get_attachment_url( $post_id );
if ( $image_url ) {
// Ensure the image URL is properly encoded for the Google Images URL
$encoded_image_url = rawurlencode( $image_url );
$google_search_url = 'https://images.google.com/searchbyimage?image_url=' . $encoded_image_url;
printf( '<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>',
esc_url( $google_search_url ),
esc_html__( 'Search on Google', 'isc-reverse-search' )
);
}
}
}
add_action( 'manage_media_custom_column', 'isc_reverse_search_column_content_plugin', 10, 2 );
// Optional: Load plugin text domain for translations
function isc_reverse_search_load_textdomain_plugin() {
load_plugin_textdomain( 'isc-reverse-search', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded', 'isc_reverse_search_load_textdomain_plugin' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment