Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wp-seopress/ef96f0f045a8ea9010e9b2a07d38c46a to your computer and use it in GitHub Desktop.
Save wp-seopress/ef96f0f045a8ea9010e9b2a07d38c46a to your computer and use it in GitHub Desktop.
Filter the prompt sent to OpenAI to generate alt text for images
function sp_ai_openai_alt_text($prompt_alt_text, $post_id) {
$language = 'English';
$image_src = wp_get_attachment_image_src($post_id, 'full');
$prompt_alt_text = sprintf(__('Write in less than 10 words an alternative text to improve accessibility and SEO, in this language %1$s, for this image URL: %2$s.', 'wp-seopress-pro'), esc_attr($language), esc_html($image_src[0]));
return $prompt_alt_text;
}
add_filter( 'seopress_ai_openai_alt_text', 'sp_ai_openai_alt_text', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment