How to give path to image in wordpress?

I’m not 100% sure what you’re asking, but

  • Yes, the path /wp-content/uploads/2021/04/image.jpg is fixed. This is a file path on disk and the image is served directly directly from that file by your webserver without going through WordPress.
    (Unless that is you move the folder and define UPLOADS or an upload_dir hook. Then it could be somewhere else. Or if you have a multisite not a single blog.)
  • Is src="wp-content/uploads/2021/04/image.jpg" the right path to use from inside WordPress code? It would be better to ask WordPress for the upload folder base URI and construct the path from that, e.g. wp_upload_dir()['url'] . '/2021/04/image.jpg' (or perhaps using trailingslashit() too)
  • Is that the best way to get the path to an uploaded image? If your image is in the media library then instead you could save the image ID in post meta if it’s per page or in options if it’s a sitewide image and then use wp_get_attachment_image to generate the HTML for the image, which will create the path and <img> tag for you.
    This allows you to change the image from the database only and is a
    more WordPress way of doing it. However this potentially causes an
    extra database hit per page you’d avoid by hard-coding the path.