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... / 6 min read
How to... / 6 min read
How to Change the Bottom Padding Dimensions on WordPress Blocks
If you're learning to modify your WordPress site's layouts and design, you may be wondering how to change the bottom padding dimensions of some of its elements. If that's the…
Read MoreHow to... / 10 min read
How to... / 10 min read
How to Disable the “Similar Posts” Section in WordPress Blogs
If you’re diving deeper into customizing your site, you may be wondering how to disable the “Similar Posts” section that appears on the bottom, sidebar, or footer of your WordPress…
Read MoreHow to... / 8 min read
How to... / 8 min read
How to Change the Width of a Blog Post on WordPress​ (3 Methods)
If you're diving deep into WordPress web design, you'll eventually need to learn how to change the width of a blog on your WordPress site. It can improve readability or…
Read MoreHow to... / 3 min read
How to... / 3 min read
How to Hook Code Output After Content on WordPress?
When you're customizing your WordPress site, you may, at some point, need to hook the output of some custom code to appear after your post's content. Thankfully, you can easily…
Read MoreHow to... / 11 min read
How to... / 11 min read
Can You Run Multiple Blogs on WordPress?
Yes, it is possible for you to run multiple blogs on the same WordPress site at the same time. However, WordPress doesn't support multiple individual blogs by default, so you…
Read More