Alt text for images in open graph image attribute
-
Hello,
I am trying to retrieve the alt text for images in the user’s selected locale (e.g., en_US) to use as the content for theog:image:alt
meta tag, but I can’t.
I have enabled the translate media feature and have added both alt texts on the image.
In functions.php I have tried:$site_open_graph_image_id = 123; $site_open_graph_image_data = wp_get_attachment_image_src($site_open_graph_image_id, 'full'); $site_open_graph_image_url = $site_open_graph_image_data[0]; $site_open_graph_image_alt_text = get_post_meta($site_open_graph_image_id, '_wp_attachment_image_alt', true); if ( is_home() ) { echo '<meta property="og:image" content="' . esc_url($site_open_graph_image_url) . '">'; echo '<meta property="og:image:alt" content="' . esc_attr($site_open_graph_image_alt_text) . '">'; }
Is there something I can append to the get_post_meta() function in order to retrive the correct alt text, like include the language code in the meta key?
- The topic ‘Alt text for images in open graph image attribute’ is closed to new replies.