admin

Tag Archives — admin

Correctly Obtain the Path to the WordPress Admin Directory

WordPress comes with a lot of handy tools that let you have URLs and paths to some folders without having to hardcode them, such as the content_url() and get_stylesheet_directory() functions for the URL to your content folder and the absolute path to your current theme folder, repectively. You can see a list of all these functions in the Codex.

However, if we search for some function to retrieve the absolute path of the admin folder, we’re lost. We have admin_url(), get_admin_url(), network_admin_url() and get_network_admin_url() but those only gives us URLs, not paths. Our only answer is to create our own function.

Here’s How You Do It

Of course you can use something like ABSPATH . '/wp-admin', but that doesn’t offer any guarantees in case the admin folder were to be renamed at some point, let’s say manually, by a plugin, or with some rewrite rule. There’s a lot of ways thing can go wrong using that method, especially if you’re distributing your code.

What I suggest as a more proper solution is to create a function like this inside your plugin or theme:

What we’re doing here is replacing the base URL of our site with the ABSPATH constant, which contains the full path to the root folder of your WordPress installation, thus leaving the /wp-admin part (or whatever it’s called) intact. We obtain the name of the admin folder dynamically, without the need to hardcode it at any point.

You can also get the path for the network admin by just replacing the call to get_admin_url() with get_network_admin_url().

Hope this helps 🙂

Read more

How to Remove Yoast’s Google Analytics Warning in Network Admin

First of all, I admit I may be missing something here, but this issue annoys me big time, and I’m sure some people will feel the same.

So, what’s the deal? Well, I’ve been using Google Analytics for WordPress for quite a lot of time now in many installations, some of which are multisites. I love this plugin and all its functionality, and I wouldn’t change it for another one in most of the sites I run. But every time I download and install it in a multisite environment, I keep seeing a notice which reads “Google Analytics is not active. You must select which Analytics Profile to track before it can work”.

Some of you may say “why don’t you just set your Analytics Profile and stop whining?”. Well, I’d wish it was that easy. And that’s because, for some of this multisite installations, the main site is just an internal hub that will be hidden from the public, and doesn’t need to have an analytics profile set up.

Read more