WordPress.org

Ready to get started?Download WordPress

Ideas

Auto-populate Alternative Text to match Title unless otherwise specified

  1. sergeliatko
    Member

    12345

    this is the exact php i'm using under wp 3.5

    /* image SEO reminder class
     by serge liatko
     updated version 0.3
    */
    class image_seo_reminder {
    	private $allowed = array(
    		'a' => array(
    			'class' => array(),
    			'href' => array(),
    			'rel' => array(),
    			'title' => array(),
    			'target' => array()),
    		'span' => array(
    			'class' => array(),
    			'title' => array()),
    		'em' => array(),
    		'strong' => array(),
    		'u' => array(),
    		'code' => array(),
    		'sup' => array(),
    		'sub' => array(),
    		'cite' => array(),
    		'strike' => array(),
    		'br' => array()
    	);
    	public function __construct() {
    		add_action('admin_init',array($this,'admin_init'),99,0);
    	}
    	public function admin_init() {
    		add_filter( "manage_media_columns", array($this,'img_columns'),10,1);
    		add_action('manage_media_custom_column',array($this,'print_img_columns'),10,2);
    	}
    	public function img_columns($columns) {
    		$columns['image_alt'] = __('Alternative Text');
    		$columns['post_excerpt'] = __('Caption');
    		return $columns;
    	}
    	public function print_img_columns($name, $post_id) {
    		$attachment = get_post($post_id);
    		if(!is_object($attachment) || is_wp_error($attachment)) return;
    		if(substr($attachment->post_mime_type, 0, 5) == 'image') {
    			switch($name) {
    				case 'image_alt' :
    					$none = '<span style="color:#dd0000;">'. __('Empty') .'</span>';
    					$alt = stripslashes(get_post_meta($post_id, '_wp_attachment_image_alt', true ));
    					echo !empty($alt) ? $alt : $none;
    				break;
    
    				case 'post_excerpt' :
    					echo (!empty($attachment->post_excerpt)) ? trim(wptexturize(wp_kses(stripslashes($attachment->post_excerpt), $this->allowed))) : '' ;
    				break;
    			}
    		}
    	}
    }
    $image_seo_reminder = new image_seo_reminder ;

    which is great as adds extra columns on media library screen that tells (in red) "empty" when user has forgotten to add alternative text

    Posted: 1 year ago #
  2. AlecRust
    Member

    That's great, thanks for that.

    Posted: 1 year ago #
  3. sergeliatko
    Member

    12345

    you welcome

    Posted: 1 year ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    15 Votes
  • Status

    Sorry, not right now