Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a bunch of widgets that I load from php files, like so:
I added a PHP CODE widget and inside wrote:

<?php
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

3 Answers 3

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:

<?php
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

 
discard

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.