how to get wp-content folder in wordpress?
22,139
you can use content_url()
it's located with http://www.example.com/wp-content
wp-content folder.
Or for path
you can use WP_CONTENT_DIR
it'll located to wp-content
folder.
require_once(WP_CONTENT_DIR. 'uploads/folder/urls.php');
Check more info Documentation
Author by
Nathan Bernard
Updated on July 05, 2022Comments
-
Nathan Bernard almost 2 years
if my main.php file is located inside
/wp-content/plugins/myplugin/folder/folder/folder/
why including urls.php , located inside/wp-content/uploads/folder/
doesn't work with this path:include_once("../../../../../uploads/folder/urls.php");
it works only if placed inside same folder as main.php with path
('urls.php');
-
Nathan Bernard over 4 yearsstill not sure why the multiple ../ doesn't work but thanks, with the WP_CONTENT_DIR works
-
plus70 almost 4 years@NathanBernard Script is actually executed in other files which including the file. It may be the site index.php, or wp-admin index.php, or anyone. It's dynamic, so
../
or./
type relative path will get wrong. Try to put$_SERVER[PHP_SELF]
into script and echo out, that will see the actual runing file. -
phatskat about 3 yearsIt seems that
WP_CONTENT_DIR
doesn't have a trailing slash, at least in my install. Not sure if this is a recent change, but I just got an error trying to loadwp-contentvendor/...
. Heads up. -
Marco Panichi about 3 yearsOn my context (server? WordPress version? phph version?)
WP_CONTENT_DIR
doesn't have the trailing slash, so I have to writerequire_once(WP_CONTENT_DIR. '/uploads/folder/urls.php');