WordPress: How to Prevent Image Hotlinking in WordPress?

Code to Prevent Image Hotlinking in WordPress-

Go to .htaccess file and add the following code. Make sure you replace the ‘your-domain-name-here’ part with your actual domain name-

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?your-domain-name-here [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]