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.

  1. Usage – <?php admin_url( $path, $scheme ); ?>
  2. Default Usage – <?php $url = admin_url(); ?>
  3. 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.

  1. Usage – <?php site_url( $path, $scheme ); ?>
  2. Default Usage – <?php echo site_url(); ?>
  3. Read More

3. home_url()

The home_url template tag retrieves the home URL for the current site, optionally with the $pathargument appended.

  1. Usage – <?php home_url( $path, $scheme ); ?>
  2. Default Usage – <?php echo esc_url(home_url(‘/’)); ?>
  3. Read More

4. includes_url()

The home_url template tag retrieves the home URL for the current site, optionally with the $pathargument appended.

  1. Usage – <?php includes_url( $path); ?>
  2. Default Usage – <?php $url = includes_url(); ?>
  3. Read More

 

 

 

5. content_url()

The content_url template tag retrieves the url to the content area for the current site with the appropriate protocol, ‘https’ if is_ssl() and ‘http’ otherwise.

  1. Usage – <?php content_url( $path ); ?>
  2. Default Usage – <?php $url = content_url(); ?>
  3. Read More

6. wp_upload_dir()

Get an array containing the current upload directory’s path and url.

  1. wp_upload_dir( string $time = null, bool $create_dir = true, bool $refresh_cache = false);
  2. Read More

7. plugin_dir_path()

Get the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in.

  1. plugin_dir_path( string $file)
  2. Read More

8. plugin_url()

Defaults to the plugins directory URL if no arguments are supplied.

  1. plugins_url(string $path=‘’, string $plugin = ‘’)
  2. Read More
Feel free to leave your comments if you have other functions you think we should include in this topic.
Share This