1

新しい画像をアップロードするときに、画像のタイトルからデフォルトの「ファイル名」をクリアしたいと思います。以下のコードを試してみましたが、うまくいきませんでした。

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

1 に答える 1

0

最初にこの回答を確認してください。代わりに、次のコード スニペットも試すことができます (コードをfunctions.phpファイルに貼り付けます) 。

add_filter( 'wp_get_attachment_image_attributes', 'remove_image_text');
function remove_image_text( $attr ) {
    unset($attr['alt']);
    unset($attr['title']);
    return $attr;
}
于 2013-04-16T17:08:45.877 に答える