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 have a bunch of widgets that I load from php files, like so:
I added a PHP CODE widget and inside wrote:

include '/wp-content/themes/myTheme/parts/block1.php';

This worked well on my localhost, but for some reason it stopped working
when I uploaded that website online (and switched the home and site_url of course).

Any ideas?

share|improve this question
up vote 2 down vote accepted

The correct way to load a PHP file in the theme directory is to use the locate_template function.

<?php locate_template(array('parts/block1.php'),true,false); ?>

The true makes it automatically require it. The false makes it not require_once it.

share|improve this answer

I've had similar problems. You may want to use the built in WordPress constants:

include WP_CONTENT_URL.'/themes/myTheme/parts/block1.php';
share|improve this answer

I included the file product-menu.php by using

<?php get_template_part( 'product-menu'); ?>

and I thought I'd put a code into the top of it to mark it as being the product menu - but turns out that I didn't

share|improve this answer

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.