Whether you’re optimizing your website for SEO, troubleshooting errors, or reorganizing content, knowing how to search for slugs in a WordPress website can save you a lot of time and effort.
In this article, we’ll explore 5 methods you can use to inspect a post or page’s slug. Some of them involve simply navigating WordPress’s admin interfaces, while others involve PHP code.
Let’s get into it.
Key Takeaways
- Slugs are user and search-engine-friendly URL elements that identify specific pages or posts.
- You can search URLs with the Quick Edit feature, plugins, your sitemap, or custom PHP functions.
What Are Slugs and Why Search for Them in WordPress?
A slug is the user-friendly, SEO-optimized portion of a URL that comes after your domain name. For example, the slug for the URL www.example.com/about-us
is about-us
.
Slugs are important in defining your website’s structure, improving readability, and boosting search engine rankings because they make your site more accessible to search engines.
You may need to search for slugs while troubleshooting behavior. You may also need slugs to pass them into functions or to display them to the user for some feature.
Regardless of the reason, understanding how to search for and manage slugs allows you to streamline your workflows and keep your WordPress site running smoothly.
5 Methods to Search Slugs in a WordPress Website
These are 5 of the easiest and quickest ways to search for slugs on a WordPress website. There are probably many more, but these ones will allow you to learn how to search them and explore new methods on your own later.
Method 1: Search Page and Post Slugs Using the Quick Edit Feature
The easiest way to find a post or page’s specific slug is using WordPress’s Quick Edit feature. Go to Posts > All Posts or Pages > All Pages and click on Quick Edit under the post or page you want to check.
The Quick Edit menu allows you to check and modify some metadata, including the content’s slug. You can also do this for custom post types.
Alternatively, you could click on Edit and check the slug on the right-hand sidebar.
If you have Yoast SEO installed, you can also scroll all the way down and find the slug in Yoast’s settings.
Method 2: Use a Plugin to Display Slugs as a Column in the Dashboard
There are many plugins out there that make using WordPress a little bit easier.
If all you want to do is make slugs more easily accessible to anyone browsing the admin dashboard, there’s a plugin for that.
Admin Slug Column does exactly what the name implies: add a new column to the admin interface with each post or page’s slug.
To get it, go to Plugins > Add New Plugin from the admin dashboard. Type in “Admin Slug Column” in the search bar.
Install and activate Admin Slug Column.
Once activated, you will see a new URL Path column appear in the All Posts and All Pages sections of the admin dashboard.
This will allow you to quickly check each post or page’s slug.
It even works on custom post types! We have a CPT called “Resources,” and this plugin provides us with the slug for each of these, too.
Method 3: Search for Slugs Using Your Sitemap
A slightly unconventional but valid way of checking slugs on your WordPress website is to use your sitemap, too.
Most likely, your sitemap is located at:
https://your-domain-goes-here.com/wp-sitemap.xml
Here’s our sitemap as of the time of writing:
You can follow each link and check most slugs on your site.
Method 4: Get the Current Post or Page’s Slug Using the Global $post Variable
You can also use a custom PHP function to extract and output the current post or page’s slug.
Paste the following in your theme’s functions.php
file. The functions.php
file is located at wp-content > themes > your-theme
.
/**
* Detects the slug of the current page or posts and displays it before the content
*/
if ( ! function_exists( 'display_current_slug' ) ) :
function display_current_slug ($content) {
if (is_singular()) {
global $post;
$current_slug = $post->post_name;
$slug_paragraph =
'<p><strong>This page\'s slug is:</strong> ' . $current_slug . '</p>';
$content = $slug_paragraph . $content;
}
return $content;
}
endif;
add_filter('the_content', 'display_current_slug');
The current slug will appear at the beginning of the content:
This function works on pages, posts, and custom posts.
Method 5: Get the Current Post or Page’s Slug Using get_post_field
An alternative to the previous function is using get_post_field
. This function retrieves data from a post field based on Post ID.
Here’s how you can use it to capture and display the current post’s slug.
/**
* Detects the slug of the current page or posts and displays it before the content
*/
if ( ! function_exists( 'display_current_slug' ) ) :
function display_current_slug ($content) {
if (is_singular()) {
$current_slug = get_post_field( 'post_name', get_post() );
$slug_paragraph =
'<p><strong>Slug:</strong> ' . $current_slug . '</p>';
$content = $slug_paragraph . $content;
}
return $content;
}
endif;
add_filter('the_content', 'display_current_slug');
This is the result:
Start Searching and Finding Your WordPress Slugs
There are multiple ways to search and find WordPress slugs. This article just presents some of the easiest and quickest ones.
Hopefully, you now know how to search for slugs on your WordPress site, and you can use this knowledge to customize it to your preferences and needs.
If you found this post useful, read our blog and developer resources for more insights and guides!
Related Articles
How to... / 5 min read
How to... / 5 min read
How to Test if Your Current WordPress Page Is a Custom Post Type?
If you're customizing your site and performing specific actions for certain content, it may be useful to test if your current WordPress page is a custom post type. This way,…
Read MoreWordPress 101 / 6 min read
WordPress 101 / 6 min read
Storyblok or WordPress to Build Your Site? Our Experience as an Agency
With new CMSs popping up every year, you may wonder whether your site would benefit from the newer, up-and-coming Storyblok or WordPress, the CMS veteran that powers nearly half the…
Read MoreHow to... / 5 min read
How to... / 5 min read
How to Add HTML to the Body of a WordPress Post or Page
So, you want to add your own custom HTML to the body of your WordPress posts and pages, huh? That's great. Adding custom HTML code is an excellent way to…
Read MoreHow to... / 7 min read
How to... / 7 min read
How to Use .htaccess to Block an IP Address From the WordPress Login Page
.htaccess (hypertext access) is a configuration file used to add or change features on websites hosted using Apache Web Server, a free and open-source web server software. The .htaccess file…
Read MoreHow to... / 5 min read
How to... / 5 min read
Can You Hide Your WordPress Site While Editing it?
Sometimes, you want to edit your WordPress site but keep the changes private until you’re ready to make them public. If that’s what you need right now, you may be…
Read More