Nol Franklin
Nol Franklin

Reputation: 33

How do you clear the default attachment title from Wordpress 3.5 uploads?

I would like to clear the default "filename" from the image title when I upload a new image. I tried using the code below with no luck.

    add_action( 'add_attachment', 'my_upload_title', 99 );
        function my_upload_title( $attachment_ID ) {
        $the_post = array();
        $the_post['ID'] = $attachment_ID;
        $the_post['post_title'] = '';
        wp_update_post( $the_post );    
    }

Upvotes: 1

Views: 238

Answers (1)

The Alpha
The Alpha

Reputation: 146219

At first check this answer and alternatively you can try the following code snippet too (paste the code in your functions.php file)

add_filter( 'wp_get_attachment_image_attributes', 'remove_image_text');
function remove_image_text( $attr ) {
    unset($attr['alt']);
    unset($attr['title']);
    return $attr;
}

Upvotes: 0

Related Questions