WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having trouble including an external .php file into my WordPress theme.

WordPress installation URL: mydomainname.com/blog

PHP File URL: mydomainname.com/testing/assets/inc/analytics.php

I'm trying to include this PHP file from within header.php of my WordPress theme.

My line of code looks like this:

<?php include ( site_url() . '/testing/assets/inc/analytics.php' );  ?>

I've also tried variations of PATH and ABSPATH but I can't get it to work. Interestingly, when I change the include to require_once it breaks the site.

Please help me figure out what exactly I'm doing wrong. Thank you!

share|improve this question
up vote 1 down vote accepted

You need to use file paths, not urls, so if mydomainname.com/blog is at /home/account/public_html/blog then your file is /home/account/public_html/testing/assets/inc/analytics.php.

I would recommend putting it into a one-off plugin though.

share|improve this answer
Thanks for the tip! This appears to be working. Unfortunately putting these files into a WordPress plugin is not an option for this project, but I will keep it in mind for the next time around. – Evster Nov 6 '13 at 19:26

how about this one:

$path = dirname( ABSPATH );
include( $path . "/testing/assets/inc/analytics.php" );
share|improve this answer
Thanks for this awesome tip! This will keep things nicely in sync between my dev server and the live server. I'd give you an up-vote, but I need more rep points first. – Evster Nov 6 '13 at 19:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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