8 Functions You Should Know to Determining Paths In WordPress Development
When creating WordPress plugins or customize child themes, you will often need to reference files and folders. Hard-coded paths should never be used in WordPress development. It will cost a painful headache when you transfer your site from Dev to live.
Good news is WordPress has a set of functions to determine the path to the wp-content and plugins directories. We can use these functions to verify that relative paths with no more headaches. Here are 8 functions will help to determining paths.
1. admin_url()
The admin_url template tag retrieves the url to the admin area for the current site with the appropriate protocol.
- Usage – <?php admin_url( $path, $scheme ); ?>
- Default Usage – <?php $url = admin_url(); ?>
- Read More
2. site_url()
The site_url template tag retrieves the site url for the current site (where the WordPress core files reside) with the appropriate protocol.
- Usage – <?php site_url( $path, $scheme ); ?>
- Default Usage – <?php echo site_url(); ?>
- Read More
3. home_url()
The home_url template tag retrieves the home URL for the current site, optionally with the $pathargument appended.
- Usage – <?php home_url( $path, $scheme ); ?>
- Default Usage – <?php echo esc_url(home_url(‘/’)); ?>
- Read More
4. includes_url()
The home_url template tag retrieves the home URL for the current site, optionally with the $pathargument appended.
- Usage – <?php includes_url( $path); ?>
- Default Usage – <?php $url = includes_url(); ?>
- Read More
6. wp_upload_dir()
Get an array containing the current upload directory’s path and url.
- wp_upload_dir( string $time = null, bool $create_dir = true, bool $refresh_cache = false);
- Read More
7. plugin_dir_path()
Get the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in.
- plugin_dir_path( string $file)
- Read More
8. plugin_url()
Defaults to the plugins directory URL if no arguments are supplied.
- plugins_url(string $path=‘’, string $plugin = ‘’)
- Read More