• fantasy_5

    (@fantasy_5)


    Hi!

    I would like to know if there’s a function that exists that can automatically specify image dimensions, add alt tags, and titles for featured images wheres as the code can be added to the theme function.php file.

    I believe the code below will set the thumbnail size

    set_post_thumbnail_size(174, 174, true);

    This one automatically adds the post title as alt attribute

    /* Register callback function for post_thumbnail_html filter hook */
    add_filter( 'post_thumbnail_html', 'meks_post_thumbnail_alt_change', 10, 5 );
    
    /* Function which will replace alt atribute to post title */
    function meks_post_thumbnail_alt_change( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
    
    	$post_title = get_the_title();
    	$html = preg_replace( '/(alt=")(.*?)(")/i', '$1'.esc_attr( $post_title ).'$3', $html );
    
    	return $html;
    
    }

    I believe this code adds the alt text via jquery where no alt text exists

    function add_custom_script(){
    ?>
    <script>
    jQuery(window).load(function(){
    	   jQuery("img").attr("alt", jQuery("title").text());
    });
    </script>
    <?php
    }
    add_action('wp_footer', 'add_custom_script');

    I’m looking for a way to create something that will pull all of the necessary information for SEO purposes. My specify image dimensions score is an F. The main sizes for dimensions that will be used on my homepage are as follows:
    Images 1920 x 900, 236 x 111, 174 x 174, 353 x 199
    My website is

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Function to specify featured image dimensions’ is closed to new replies.