Search code examples
wordpressrequire

Some error → HTTP request failed! HTTP/1.1 404 Not Found


require_once(get_stylesheet_directory_uri().'/inc/widgets/MCAPI.class.php');

I am getting the above error. Actually previously it was pulling the file from here:

require_once(plugin_dir_path(__FILE__).'MCAPI.class.php');

But I have transferred the file into my theme folder of WordPress here: inc/widgets/MCAPI.class.php

and used this path:

require_once(get_stylesheet_directory_uri().'/inc/widgets/MCAPI.class.php');

But is throwing error:


Warning: require_once(http://......../wp-content/themes/puck/inc/widgets/MCAPI.class.php): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home2/kisskiss/public_html/....../wp-content/themes/puck/functions.php on line 238

Fatal error: require_once(): Failed opening required 'http://...../wp-content/themes/puck/inc/widgets/MCAPI.class.php' (include_path='.:/opt/php54/lib/php') in /home2/kisskiss/public_html/....../wp-content/themes/puck/functions.php on line 238


Solution

  • You're using get_stylesheet_directory_uri() which returns an URL while you need a path. You should use get_template_directory() so your require_once should look like this:

    require_once(get_template_directory().'/inc/widgets/MCAPI.class.php');