Enter

How to... / 5 min read

How to Search for Slugs in a WordPress Website (5 Methods)

closeup of a laptop keyboard while someone uses it. A digital illustration of a search bar hovers on top of the laptop

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 All Posts interface in WordPress's admin dashboard

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.

Highlighting the slug field in WordPress's Quick Edit feature

Alternatively, you could click on Edit and check the slug on the right-hand sidebar.

The WordPress "Link" field inside the Gutenberg editor represents the post's slug

If you have Yoast SEO installed, you can also scroll all the way down and find the slug in Yoast’s settings.

A WordPress post's slug as seen in Yoast SEO'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.

The WordPress plugin repository in the admin dashboard. The user is searching for the Admin Slug Column plugin

Once activated, you will see a new URL Path column appear in the All Posts and All Pages sections of the admin dashboard.

The "All Pages" interface in WordPress's admin dashboard displaying a new "URL Path" column that provides the slug for each page

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.

A WordPress interface that lists all posts that belong to a "Resources" custom post type. There's a new "URL Path" column that provides the slug for each resource

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:

An XML sitemap for a WordPress site

You can follow each link and check most slugs on your site.

An XML sitemap for a WordPress 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:

A WordPress post displaying its own slug in the first paragraph

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:

A WordPress post displaying its own slug in the first paragraph

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!