• For SEO purposes it would be better to use parent post title, if available.
    Made s small patch:
    1) checks if parent post title is available and uses it instead;
    2) is addition to “title” also replaces “Alt field”.
    This two small changes make this plugin perfect for SEO.

    function fmt_update_media_title($id) {
    
    	$options = get_option('fmt_options');
    	$cap_options = $options['rdo_cap_options'];
    
    	$uploaded_post_id = get_post( $id );
    	/* mod! */
    	if ($uploaded_post_id->post_parent) {
        	$parent_post = get_post( $uploaded_post_id->post_parent );
        	$title = $parent_post->post_title;
        	if ($title && $parent_post->post_status!='auto-draft'){
            	$uploaded_post = array();
            	$uploaded_post['ID'] = $id;
            	$uploaded_post['post_title'] = $title;
            	wp_update_post( $uploaded_post );
        	    update_post_meta($id, '_wp_attachment_image_alt', $title);
        	    return true;
        	}
    	}
    	/* mod! */
    	$title = $uploaded_post_id->post_title;
    
    	/* Update post. */
    	$char_array = array();
    	if( isset($options['chk_hyphen']) && $options['chk_hyphen'] ) $char_array[] = '-';
    	if( isset($options['chk_underscore']) && $options['chk_underscore'] ) $char_array[] = '_';
    	if( isset($options['chk_period']) && $options['chk_period'] ) $char_array[] = '.';
    	if( isset($options['chk_tilde']) && $options['chk_tilde'] ) $char_array[] = '~';
    	if( isset($options['chk_plus']) && $options['chk_plus'] ) $char_array[] = '+';
    
    	/* Replace chars with spaces, if any selected. */
    	if( !empty($char_array) )
    		$title = str_replace($char_array, ' ', $title );
    
    	/* Trim multiple spaces between words. */
    	$title = preg_replace("/\s+/", " ", $title);
    
    	/* Capitalize Title. */
    	switch ($cap_options) {
        case 'cap_all':
    		$title = ucwords( $title );
            break;
        case 'cap_first':
    		$title = ucfirst( strtolower( $title ) );
            break;
        case 'all_lower':
    		$title = strtolower( $title );
            break;
        case 'all_upper':
    		$title = strtoupper( $title );
            break;
        case 'dont_alter':
    		/* Leave title as it is. */
            break;
    	}
    
    	// Update the post into the database
    	$uploaded_post = array();
    	$uploaded_post['ID'] = $id;
    	$uploaded_post['post_title'] = $title;
    	wp_update_post( $uploaded_post );
    	update_post_meta($id, '_wp_attachment_image_alt', $title); // mod!
    }

    https://pastebin.com/nNpjCsPN

    https://www.ads-software.com/extend/plugins/format-media-titles/

  • The topic ‘Use parent post title if possible’ is closed to new replies.