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!

2 Answers 2


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.

  • 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
    Commented Nov 6, 2013 at 19:26

how about this one:

$path = dirname( ABSPATH );
include( $path . "/testing/assets/inc/analytics.php" );
  • 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
    Commented Nov 6, 2013 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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