Jump to content

ALT image on wordpress plugin


El_toro

Recommended Posts

Hello all,

I'm a total newbie to the PHP, and my knowledge is practically close to zero, so please don't judge me for this question.

I am using a WordPress plugin called Automatic Featured Image Posts. It does a great job creating a draft post from a newly uploaded image. In the functions.php file, there's this filter:

    add_filter( 'afip_new_post_content', 'myprefix_change_afip_post_content', 10, 2 );
/* Grabs the image source for the newly created image and inserts it
 * into the new post content along with a one line paragraph. */
function myprefix_change_afip_post_content( $post_content, $attachment_id ) {
    $my_uploaded_image = wp_get_attachment_image_src( $attachment_id );

    $post_content = '<p>This is my new uploaded image....</p>';
    $post_content .= '<img src="' . $my_uploaded_image[0] . '">';
    return $post_content;
}

It works perfectly, but there's one problem - it doesn't add an alt tag. I want the alt tag to be the same as the name of the picture that the plugin uploads to the post. Since I am a total noob I just tried to modify this line just to check out if it works:

    $post_content .= '<img src="' . $my_uploaded_image[0] . '" alt="' . $attachment_id . '">';

And it did. But it's obviously not the thing I am looking for. It just puts in the number of the attachment. Now, I know that Image's 'alt' text is stored as a string in wp_postmeta with the meta_key of '_wp_attachment_image_alt'. However,  I still don't know how should I add the image title as an alt into this code.

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.