2013-04-16 45 views
1

我想在上传新图像时清除图像标题中的默认“文件名”。我尝试使用下面的代码,没有运气。如何清除WordPress上传的默认附件标题?

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

回答

0

首先检查一下this answer还或者,你可以试试下面的代码片段太(代码粘贴在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; 
} 
+0

感谢您的快速回复@Shiekh Heera!不幸的是,这两个答案在WP 3.5中似乎都不起作用。 有趣的是,图像对齐,链接类型和大小有一个“update_option”函数。 –