The wp-admin are of my site is available via https only; for that reason any use of get_template_directory_uri(); in the admin area generates a url as such https://mysite.co.uk/...

I am able to successfully enqueue scripts and styles using get_template_directory_uri(); however when I attempt to use simplexml_file_load(); to access a local xml document in the admin area of the site, the file fails to load.

I can get around this by hardcoding a non https version of my theme directory, but for obvious reasons, this isn't practical.


simplexml_load_file(get_template_directory_uri().'/myxml.xml'); - does not work simplexml_load_file('https://mysite.co.uk/my-theme/myxml.xml'); - does not work simplexml_load_file('http://mysite.co.uk/my-theme/myxml.xml'); - does work


In case this helps anyone in the future:

The problem was not a WordPress issue, it was a server configuration issue.

Useful explanation on checking which stream wrappers are enabled on your server (used this to make sure https was enabled on my server) Enable Stream Wrappers

Someone with the same issue found that their certificate failed to verify: Certificate Verification Fails

The issue was fixed by our hosting provider, with the following explanation:

The problem is caused by the the self signed certificate on the server. We could either allow the self signed certificate in the php setup or load a valid SSL certificate.

The issue was fixed by creating a self signed certificate which matches the Openssl common name. This fixed all libxml errors


You've loaded the xml file using an URL of your own web server. While your solution fixes the problem, it wasn't necessary to load the xml using URL (HTTP or HTTPS) in the first place. Since it's on the same server, you could've loaded the xml file using file PATH instead.

Note: get_template_directory_uri() function returns URL, whereas, get_template_directory() function returns local file PATH.

So instead of:

simplexml_load_file( get_template_directory_uri() . '/myxml.xml' );

CODE, you can use:

simplexml_load_file( get_template_directory() . '/myxml.xml' );

This way, there will be no local URL issue at all & it's much faster.

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.