Can't perform require once in WordPress without displaying the path on the page - wordpress

Followng accepted answers given here I used the following to call some PHP code on my home page:
require_once (bloginfo('template_directory') . '/home_bloc_horaires.php');
It works, but it also actually displays the path of my template directory on my page! Any way to avoid this?
EDIT:
Tried require_once(get_template_directory().'/home_bloc_horaires.php'); : it doesn't work and I get the following error messages:
Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in D:\EasyPHP\www\wordpress\wp-content\themes\mmt-2014\header.php on line 348
Warning: include(http://127.0.0.1/wordpress/mirail/wp-content/themes/mmt-2014/home_bloc_horaires.php): failed to open stream: no suitable wrapper could be found in D:\EasyPHP\www\wordpress\wp-content\themes\mmt-2014\header.php on line 348
Warning: include(): Failed opening 'http://127.0.0.1/wordpress/mirail/wp-content/themes/mmt-2014/home_bloc_horaires.php' for inclusion (include_path='.;C:\php\pear') in D:\EasyPHP\www\wordpress\wp-content\themes\mmt-2014\header.php on line 348

bloginfo() outputs the result, which is why you can see it. Use this instead:
require_once(get_template_directory().'/home_bloc_horaires.php');
You can find more info on loading files in WordPress here.

Related

PHP: Error using include_once function. Failed opening 'mysiteURL' for inclusion

I have never used PHP and need it just to build my WordPress site with an installed theme.
Every time when I open any pages under my wp-admin, I'm getting a warning:
Warning: include_once(): Failed opening
‘/myURL/public_html/wp-content/plugins/dsidxpress/admin.php’
for inclusion (include_path=’.:/usr/local/php56/pear’) in
/myURL/public_html/wp-content/plugins/dsidxpress123/dsidxpress.php
on line 90
When opening .php, I see the following code on line 90:
include_once(str_replace("\\", "/", WP_PLUGIN_DIR) . "/dsidxpress/admin.php");
After changing it per the instrucions:
include_once(include_path='.:/usr/local/php56/pear' . “/dsidxpress/admin.php”);
I'm getting new error:
Parse error: syntax error, unexpected ‘=’ in /myURL/public_html/wp-content/plugins/dsidxpress123/dsidxpress.php on line 90
How exactly do I need to change it?

I am having the issue in wp site

I am having the following issue in wp site.
Warning: include(/home2/ngohost/public_html/artfinteriors.com/wp-content/plugins/wp-super-cache/wp-cache-base.php): failed to open stream: No such file or directory in /home/ngohost/public_html/artfinteriors.com/wp-content/plugins/wp-super-cache/wp-cache.php on line 65
Warning: include(): Failed opening '/home2/ngohost/public_html/artfinteriors.com/wp-content/plugins/wp-super-cache/wp-cache-base.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/ngohost/public_html/artfinteriors.com/wp-content/plugins/wp-super-cache/wp-cache.php on line 65
Warning: include_once(/home2/ngohost/public_html/artfinteriors.com/wp-content/plugins/wp-super-cache/ossdl-cdn.php): failed to open stream: No such file or directory in /home/ngohost/public_html/artfinteriors.com/wp-content/plugins/wp-super-cache/wp-cache.php on line 82
Warning: include_once(): Failed opening '/home2/ngohost/public_html/artfinteriors.com/wp-content/plugins/wp-super-cache/ossdl-cdn.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/ngohost/public_html/artfinteriors.com/wp-content/plugins/wp-super-cache/wp-cache.php on line 82
Warning: Cannot modify header information - headers already sent by (output started at /home/ngohost/public_html/artfinteriors.com/wp-content/plugins/wp-super-cache/wp-cache.php:65) in /home/ngohost/public_html/artfinteriors.com/wp-includes/pluggable.php on line 1179
It seems that you are using WP Super Cache plugin and this is causing the errors. The first step for debugging is to try to deactivate / uninstall the plugin and see if the error still appear.

WordPress error with require_once

I have this error in my wordpress, on frontend and dashboard:
Warning: require_once(includes/theme-widgets.php) [function.require-once]: failed to open stream: No such file or directory in /home/masqueci/public_html/functions.php on line 2
Fatal error: require_once() [function.require]: Failed opening required 'includes/theme-widgets.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/masqueci/public_html/functions.php on line 2
The problem is that I try to delete this line, rename the file, delete the all theme and delete wp-admin and wp-include and upload it again. But the error continue. How can I fix this problem?
Your problem is that you are using a worng reletive path to the file wanted.
Try on using:
$filePath = get_bloginfo('template_url'); // this line gets you the path to the current theme.
$filePath .= 'includes/theme-widgets.php'; // now we add the relative path to your file
require_once($filePath); // now we place the hole thing inside the 'require_once' function.
now you can minimize the code by:
require_once(get_bloginfo('template_url').'includes/theme-widgets.php');
what was originally responded by the function was that it was trying on going to:
public_html/includes/theme-widgets.php which did not exist while your path was:
public_html/wp-content/themes/{theme_name}/includes/theme-widgets.php
The code i have provided before should do the job for you :)

Fatal error when copying wordpress site from server to localhost

I've been trying to create a local copy of this wordpress site - click4taps.co.uk. But even though everything seems to run pretty much fine on the server, on localhost I am getting these code errors, I would have maybe expected a database error if I had forgot something in the setup. I'm not super good at php but I can't see anything that out of place in the code the error specifies.
Here is the error message I receive when trying to launch the site in localhost:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'woocommerce_layered_nav_init' not found or invalid function name in C:\Program Files (x86)\Ampps\www\click4taps\wp-includes\plugin.php on line 406
Fatal error: Call to undefined function is_product() in C:\Program Files (x86)\Ampps\www\click4taps\wp-content\themes\bazar\theme\plugins\woocommerce-ajax-layered-nav\init.php on line 59
Any feedback on this would be very helpful thanks
Activate your woocommerce plugin

Body and Footer gone on homepage and error message after clearing cache Drupal 7

I recently was working on my website and decided to clear all caches and now the homepage only shows the header and nothing else. All the other pages work fine but i do get this error:
Warning: include(page-front.php) [function.include]: failed to open
stream: No such file or directory in include() (line 14 of
/home/anthonyd/public_html/graphicimpress/sites/all/themes/gi_0612/page.tpl.php).
Warning: include(page-front.php) [function.include]: failed to open
stream: No such file or directory in include() (line 14 of
/home/anthonyd/public_html/graphicimpress/sites/all/themes/gi_0612/page.tpl.php).
Warning: include() [function.include]: Failed opening 'page-front.php'
for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in
include() (line 14 of
/home/anthonyd/public_html/graphicimpress/sites/all/themes/gi_0612/page.tpl.php).
I did see a very similar problem someone else posted but it was for drupal 6 and the fix was to rebuild the modules by visiting admin/build/modules
and rebuild themes by visiting admin/build/themes. Unfortunately D7 does not have the same menu options.
Does anyone have an idea how to fix this?
In your file /home/anthonyd/public_html/graphicimpress/sites/all/themes/gi_0612/page.tpl.php on line 14, function include('page-front.php') trying to include file page-front.php into your page.tpl.php, but there's no such file as page-front.php.
Make sure that this file (page-front.php) exist, or remove include('page-front.php') from page.tpl.php.

Resources