Website Building » WordPress » How do I display images in WordPress?

How do I display images in WordPress?

Last updated on January 23, 2023 @ 2:20 pm

Images can be displayed in WordPress by uploading them to the WordPress media library, or by using the include_once and require_once functions. To include an image in a post or page, use the includes tag:

<img src="myimage.jpg" alt="my image title" />

To require an image be included in a post or page, use the require_once function:

require_once(‘myfile.php’);

The size of an image can be specified in pixels, or as a percentage of the post or page’s total size. To specify a size in pixels, use the src attribute with a value of “widthxheight”.

PRO TIP: When adding images to a WordPress post or page, be sure to add the “alt” and “title” attributes. These attributes provide information about the image for search engines and screen readers.

To specify a size as a percentage of the post or page’s total size, use the sizes attribute with a value of “widthxheight%.png”.

The src and sizes attributes can also be used to link to files on your server. To do this, use the href attribute and specify the full path to the file.

For more information on using images in WordPress, please see the WordPress Codex.

Dale Leydon

Dale Leydon

Sysadmin turned Javascript developer. Owner of 20+ apps graveyard, and a couple of successful ones.