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

Share:
22,139
Nathan Bernard
Author by

Nathan Bernard

Updated on July 05, 2022

Comments

  • Nathan Bernard
    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
    Nathan Bernard over 4 years
    still not sure why the multiple ../ doesn't work but thanks, with the WP_CONTENT_DIR works
  • plus70
    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
    phatskat about 3 years
    It 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 load wp-contentvendor/.... Heads up.
  • Marco Panichi
    Marco Panichi about 3 years
    On my context (server? WordPress version? phph version?) WP_CONTENT_DIR doesn't have the trailing slash, so I have to write require_once(WP_CONTENT_DIR. '/uploads/folder/urls.php');