There are some really useful functions for URLs in WordPress, in particular home_url(), admin_url() and plugins_url().


home_url() takes two arguments: $path and $scheme (both optional) and you can use it like this:

<?php echo home_url( '/blog/' ) ?>

On this site, this will echo:

Without arguments home_url() will return the option ‘home’ stored in the database, which lacks a trailing slash, so if you’re using this function to point to the landing page of your site you should probably add the slash:

<a href="<?php echo home_url( '/' ) ?>"><?php _e( 'Home', 'olab' ) ?></a>

This will echo <a href="">Home</a>

You can find more details in the codex.


admin_url() will print out a URL to wp-admin on your site. For example:

<a href="<?php echo admin_url() ?>"><?php _e( 'Admin', 'olab' ) ?></a>

will echo

NB: admin_url() does add a trailing slash so you should use it like this:

<a href="<?php echo admin_url( 'upload.php' ) ?>"><?php _e( 'Upload files', 'olab' ) ?></a>

This will echo <a href="">Upload files</a>

Again, check out the codex.


plugins_url() is also useful. It takes 2 (again, optional) arguments: $path and $plugin. $path the is the relative path to the file you’re after so:

<img src="<?php echo plugins_url( '/my-plugin-dir/images/image.png' ) ?>">


But this isn’t a good way to use it as you can never be sure what WordPress will name your plugin folder! Instead, as the second paramater ($plugin) you can pass PHP’s magic constant __FILE__ like so: (this example is taken directly from the codex page):

<img src="<?php echo plugins_url( 'images/image.png', __FILE__ ) ?>">

Which will give you the path relative to the file you call the function from. The URL will be something like:

There are some other similarly useful functions, namely:

    site_url() // The site directory URL ( or
    includes_url() // The wp-includes directory URL (
    content_url() // The wp-content directory URL (