php syntax – how to concatenate properly – echo bloginfo(‘stylesheet_directory)

  1. bloginfo() does already an echo. It will be printed before everything else in your echo statement. Use get_bloginfo() instead.

  2. stylesheet_directory is one of these arguments where it is better just to use the function that is called by WordPress: get_stylesheet_directory_uri(). It is easier to understand, especially in this case where one could expect a path by looking at the name of the argument string.

  3. If you are using an URL provided by a WordPress function, escape it. Always.

  4. For better readability, I would use printf() here.

Summary

printf( 
    '<img src="https://wordpress.stackexchange.com/questions/258195/%s/img/ogpimage.png" alt="Blog Posts Placeholder">',
    esc_url( get_stylesheet_directory_uri() )
);