---
title: Filter the prompt sent to AI to generate alt text for images
url: "https://www.seopress.org/support/hooks/filter-the-prompt-sent-to-openai-to-generate-alt-text-for-images/"
lang: en-US
updated: 2026-03-10
hook_name: seopress_ai_{provider}_alt_text
required_version: 7.1
---

# Filter the prompt sent to AI to generate alt text for images

- **Hook name:** `seopress_ai_{provider}_alt_text`
- **Required version:** 7.1

```php
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 );
```

Source: [https://gist.github.com/wp-seopress/ef96f0f045a8ea9010e9b2a07d38c46a](https://gist.github.com/wp-seopress/ef96f0f045a8ea9010e9b2a07d38c46a)


 

Replace `{provider}` by the AI provider name:

- openai
- deepseek
- gemini
- mistral
- claude
