0

In my theme, many URLs are generated based on bloginfo('template_directory'), for example, below is a snippet in the header

  <link rel="apple-touch-icon" sizes="64x64" href="<?php bloginfo('template_directory'); ?>/apple-touch-icon.png">

Now for my site origin.example.com, I have create a Cloudfront distribution xxx.cloudfront.net.

To make sure the URLs in the web pages will use the URLs in xxx.cloudfront.net, not origin.example.com, I modify wp-config.php and add the following lines:

define( 'WP_SITEURL', 'https://xxx.cloudfront.net' );

define( 'WP_HOME', 'https://xxx.cloudfront.net' );

However, even after this, when I load a page from https://origin.example.com, I still see this:

<link rel="apple-touch-icon" sizes="64x64" href="https://origin.example.com/wp-content/themes/datanumen/apple-touch-icon.png">

So I doubt whether bloginfo('template_directory') is generated based on WP_SITEURL and WP_HOME, or actually based on other values in the database?

I check https://developer.wordpress.org/reference/functions/bloginfo/ and it does not mention that clearly, in the comment there is an example implies that the values comes from WP_SITEURL and WP_HOME.

Update

There must be something wrong. I have:

  1. Add the following line to wp-config.php:
define( 'WP_CONTENT_URL', 'https://xxx.cloudfront.net' );
  1. Use "Better Search Replace" to replace all origin.example.com with xxx.cloudfront.net.

  2. Deactive WP Rocket so that cache will not working.

Even doing all these, my page still use https://origin.example.com/wp-content/themes/xxx/ as the value of bloginfo('template_directory').

1 Answer 1

0

The URL used by bloginfo('template_directory') is based on various functions that determine the URL to the theme directory, which are ultimately based on the WP_CONTENT_URL constant, which is the URL to the wp-content/ directory.

The initial value for this constant, if you don't define it yourself, is based on the site URL set in the database, in Settings > General.

In your case, based solely on your question because I don't really know Cloudfront, you probably want something like this:

define( 'WP_CONTENT_URL', 'https://xxx.cloudfront.net/wp-contebt' );

As far as I can tell, normally WP_CONTENT_URL will use WP_SITEURL, but this does not happen on multisite installations, which you must be using.

1
  • Thank you. I think there must be something wrong, I have follow your instructions to add the define statement, I also use Better Search Replace to replace all strings with cloudfront URLs, and I have disactivate the WP Rocket, but my page still use origin.example.com/xxx as the bloginfo('template_directory').
    – alancc
    Sep 21, 2021 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.