简体   繁体   中英

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 );    
    }

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM