Friday , 17 November 2017
Home / Programming / WordPress / Plugins / WordPress URL Functions – WordPress Plugin Tutorial
WordPress URL Functions
WordPress URL Functions

WordPress URL Functions – WordPress Plugin Tutorial

This post is part of the WordPress Plugin tutorial series. To find a link to all tutorials in order, then please click here.

We just recently learned about the plugins_url() function and how handy it can be when we need to grab files from our own plugin. There are other WordPress URL functions which will be quite handy.

Let’s create a new plugin.  Every time we create a new plugin, it’ll be based off the template plugin. So, I won’t be saying to copy the template plugin anymore. Just assume that you should copy the template plugin unless I state otherwise.

Our new plugin will be named wpURLex. Copy and paste the following code in your index.php file.

Nothing, new here.  We’re hooking into the wp_footer hook and we’ll be echoing out some code in our jk_show_wp_urls() function.

WordPress URL Functions

Here’s what our func.inc.php file looks like.

It’s pretty simple. All we’re doing is echoing out each function to see the result. Some of these WordPress URL functions are used when creating themes, but they can be useful if you want to use them in your plugin.

Activate your plugin and then visit your WordPress site and scroll down. If you would like a full list of available WordPress URL  functions, check here. I created this lesson because most WordPress URL functions from that link are scattered. There are quite a few. So, I’m giving you some important and more common ones for you to use.

WordPress URL Functions
WordPress URL Functions

Here’s a breakdown of all the functions we used.

  • get_theme_root() –  returns the absolute path to the themes directory
  • get_template_directory_uri() –  returns the path to the current theme(Checks for SSL as well)
  • admin_url() –  returns the path to the admin area(Checks for SSL as well)
  • content_url() –  returns the path to the content area(Checks for SSL as well)
  • includes_url() – returns the path to the includes area(Checks for SSL as well)
  • site_url() –  returns the URL for the current site(Checks for SSL as well)
  • network_site_url() –  returns the URL for the main site if the site is MU(Checks for SSL as well)

When I say it checks for SSL, I mean the function will check whether it should add use https:// or http://. SSL certificates are common for e-commerce type sites.

I highly encourage you take a look at the list of WordPress URL functions available. As we continue on, we’ll learn more about the kinds of functions there are.

About Jasko Koyn

Check Also

WordPress Meta Boxes

WordPress Meta Boxes – WordPress Plugin Tutorial

WordPress meta boxes are used to display certain information or options in a page. It’s …

Leave a Reply

Your email address will not be published. Required fields are marked *

ULTIMATE WORDPRESS DEVELOPMENT COURSE
Want to learn how to create your own custom WordPress plugins and themes? Check out my course!
Get 93% off my course. You'll also learn how to integrate WooCommerce and BuddyPress into your projects. This is a limited time offer
Yes, I would like to get 93% off your course!
No Thanks!
close-link