mincom
mincom

Reputation: 979

How to remove hardcoded domain name from WordPress links?

Wordpress loads all assets and links with an absolute URL including the domain name (e.g. <img src="https://example.com/cat.png">).

How to NOT include the domain name?

I tried editing the WP_CONTENT_URL and updating WP_SITEURL/WP_HOME with no success.

Is there a simple way of doing that?

Upvotes: 1

Views: 1245

Answers (1)

Krupal Panchal
Krupal Panchal

Reputation: 1545

You can do that by simply WordPress theme URL function get_template_directory_uri(). See the below link.

https://developer.wordpress.org/reference/functions/get_template_directory_uri/

It will give a full path to the WordPress theme. If your image path is like this

\wp-content\themes\your-theme\assets\images\image.jpg

then you can get that image path like below.

<img src="<?php echo get_template_directory_uri() . '/assets/images/image.jpg'; ?>"> 

Upvotes: 1

Related Questions