I have 3 themes set up right now and I need them all to inherit partials from the same source in order to update all three themes at the exact same time when I change any of those partials.

I'm seeing that include/require (../../../includes/vital/partial.php); doesn't work from within single.php or any other other theme template file. the error I get is:

Warning: include(): Failed opening '../../../includes/vital/partial.php' for inclusion (include_path='.:/usr/local/Cellar/php56/5.6.8/lib/php') in /Users/insertusername/Documents/Code/Projects/wordpress/wordpress-1/wp-content/themes/flowerz-mobile/single.php on line 7

How can I make this work?


1 Answer 1


Don't ever use relative paths in wordpress. use require(ABSPATH .'your path relative to wordpress root'). There are also other useful constants and API for that but selecting one will depend on where exactly do yo want your common code to be.

At the minimum it will make it easier to understand from the error message which file exactly is failing to open.

  • Ok, so it seems that just doing include('include/vital/partial.php'); worked. This seems to work from wordpress root by default. I tried using an aboslute path function within the include function and I was seeing all kinds of errors. What is the advantage of using an abs path function vs. doing it the way I just described? And what's the proper way to use an abs_path function within another function like include?
    – ninja08
    Nov 13, 2015 at 6:36
  • 1
    what is included in include('include/vital/partial.php') depends also on the php settings, the default folders in which it looks for files php.net/manual/en/ini.core.php#ini.include-path, so might actually end including something that you did not intend to. Nov 13, 2015 at 7:03
  • Ok cool. That's good to know. Now, how can I get something like include(get_bloginfo('wpurl') . 'includes/vital/partial.php'); to work? I've been searching around and reading a lot but I'm not seeing an answer. Thanks!
    – ninja08
    Nov 13, 2015 at 7:39
  • 1
    for example codex.wordpress.org/Function_Reference/get_template_directory and codex.wordpress.org/Function_Reference/get_theme_root, and there are probably more APIs of this kind that do not pop into my head right now Nov 13, 2015 at 8:52

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.