SEO & AI search · Guide
How to Get Permalink in WordPress (Step by Step)

Short answer
Open the post in the block editor and click the URL row in the sidebar to see and copy its permalink, or hover over it in the Posts list and click View. In code, use get_permalink() with a post ID, or the_permalink() inside the Loop.
Key takeaways
- The editor sidebar shows the permalink once a post is saved.
- The View link in list screens opens the live permalink.
- Settings, then Permalinks controls the pattern of every link.
- get_permalink() returns a link and the_permalink() prints it.
- Use get_term_link() for categories and tags.
- Re-save permalink settings if a link returns a 404.
How do you get a permalink in WordPress?
You get a post or page permalink from the editor sidebar or the View link in the Posts list, and in code you use get_permalink() with the post ID.
A permalink is the permanent web address of a single post, page, category or other item. WordPress builds it from your permalink settings and the item's slug.
There are two common reasons people need one. Editors want to copy a link to share or use in a menu. Developers want to print a link inside a theme or plugin.
This guide covers both. It starts with the no-code ways and then moves to the PHP functions developers use.
If you want the basics first, our explainer on what a permalink is covers how WordPress builds these addresses.
Where do you find a post's permalink in the block editor?
Open the post in the block editor, look in the settings sidebar for the URL or Link field, and click it to see and copy the full permalink.
In recent WordPress versions, the post summary in the right sidebar shows the address. Clicking it opens a small panel with the full link and the slug.
- Open Posts and click the post title to edit it.
- Make sure the settings sidebar is open. Click the panel icon at the top right if it is hidden.
- Select the Post tab, not the Block tab.
- Find the URL or Link row in the summary area.
- Click it to see the permalink and the editable slug.
- Copy the link, or click it to open the post.
On a new post, the full permalink appears only after you save a draft or publish. Before that, WordPress has no slug to build it from.
Pages work the same way. Open the page in the editor and look for the same URL row in the Page tab.
How do you get the permalink from the Posts or Pages list?
Hover over a post or page title in the list screen and use the View link, which opens the published permalink you can copy from the address bar.
This is the quickest way when you need links for several items.
- Go to Posts, then All Posts, or Pages, then All Pages.
- Hover over the title you want.
- Click View to open the live item.
- Copy the address from your browser's address bar.
You can also right-click the View link and copy the link address without opening the page.
Drafts show a Preview link instead. Preview links include query strings and are not the final permalink, so wait until the item is published.
How do you get links for categories, tags and authors?
Go to the category or tag list under Posts, hover over the name and click View, or open the archive on your site and copy its address.
Categories and tags have their own archive pages with their own permalinks.
- Categories. Open Posts, then Categories, hover over a category and click View.
- Tags. Open Posts, then Tags, and use the same View link.
- Authors. Author archives usually live at your site address plus author and the username slug.
- Custom post types. Plugins such as WooCommerce add View links in their own list screens.
The category base, such as category, is set on the Permalinks settings screen. You can change it there if you want a different word.
How do your permalink settings shape the link?
Your permalink structure under Settings, then Permalinks, controls the pattern of every link, so the same post can have a different address on a different structure.
WordPress offers several presets, including Plain, Day and name, Month and name, Numeric and Post name. You can also build a custom structure with tags.
| Structure | Example link | Notes |
|---|---|---|
| Plain | yoursite.com/?p=123 | Works everywhere, not readable |
| Day and name | yoursite.com/2026/11/21/sample-post/ | Shows the date |
| Month and name | yoursite.com/2026/11/sample-post/ | Shorter date version |
| Numeric | yoursite.com/archives/123 | Uses the post ID |
| Post name | yoursite.com/sample-post/ | Short and readable |
The WordPress guide to customizing permalinks explains each option and the available structure tags.
If you are choosing a structure for a new site, our article on the best permalink structure for SEO compares them.
To set one up, see how to set up permalinks in WordPress.
How do you get a permalink with PHP?
Use get_permalink() to return the URL of a post as a string, or the_permalink() to print the URL of the current post inside the Loop.
These two functions cover most needs in themes and plugins.
// Inside the Loop: print the current post's link
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
// Anywhere: get a link by post ID
$url = get_permalink( 123 );
echo esc_url( $url );
The difference is simple. the_permalink() echoes the link for the current post. get_permalink() returns it so you can store, change or print it yourself.
The developer reference for get_permalink() lists its parameters. It accepts a post ID or a post object and returns false if the post does not exist.
Always escape URLs before output with esc_url(). That protects against broken markup and injected values.
Which PHP function should you use for other types of content?
WordPress has a matching function for each kind of link, such as get_term_link() for categories and tags and get_post_type_archive_link() for custom post type archives.
Here is a quick reference.
| What you need | Function |
|---|---|
| Post or page link by ID | get_permalink( $id ) |
| Current post in the Loop | the_permalink() |
| Page link by ID | get_page_link( $id ) |
| Category, tag or custom term | get_term_link( $term ) |
| Category by ID | get_category_link( $id ) |
| Post type archive | get_post_type_archive_link( 'product' ) |
| Author archive | get_author_posts_url( $user_id ) |
| Site home page | home_url( '/' ) |
get_term_link() returns a WP_Error object when the term is missing, so check the result before using it. The get_term_link() reference shows a safe example.
For the current page in any template, get_permalink( get_queried_object_id() ) works on singular views.
How do you get a permalink from a post slug or title?
Find the post first with a function such as get_page_by_path() for slugs, then pass its ID to get_permalink().
Sometimes you only know the slug, for example from a settings field. You can look the post up and then build its link.
$post = get_page_by_path( 'sample-post', OBJECT, 'post' );
if ( $post ) {
echo esc_url( get_permalink( $post ) );
}
The third argument sets the post type. Use page for pages, post for posts, or your custom post type name.
Avoid looking up posts by title. Titles are not unique, and the function for that has been deprecated in recent versions of WordPress.
How do you get a permalink with WP-CLI?
Use the wp eval command to run get_permalink() with a post ID, which prints the link in your terminal without opening the dashboard.
WP-CLI is handy on servers or when you need many links at once.
wp eval 'echo get_permalink( 123 );'
The wp eval command reference explains how it loads WordPress before running your code.
To list post IDs first, use wp post list with the post type and status you need, then pass each ID to the command above.
What about the short link and the post ID link?
Every post also works at a plain address with its ID, such as yoursite.com/?p=123, and WordPress redirects that to the pretty permalink.
This plain link is useful when you know the ID but not the slug. Paste it in the browser, and WordPress sends you to the real address.
Do not use the ID link in menus or public posts. Search engines and readers should see the canonical permalink, which is the address Google is meant to index.
Google's advice on URL structure favours simple, readable addresses, which is one reason the Post name structure is popular.
What if the permalink does not work?
If a permalink returns a 404 error, re-save your permalink settings to flush the rewrite rules, then check for slug conflicts or server rewrite problems.
Go to Settings, then Permalinks, and click Save Changes without changing anything. That rebuilds WordPress's rewrite rules.
If links still fail, our guide to fixing permalinks not working covers .htaccess and server issues.
To confirm Google sees the right address, run the link through the URL Inspection tool in Search Console. It shows whether the page is indexed and which URL Google chose as canonical.
How do you change a permalink safely?
Edit the slug in the post's URL panel, save, and add a redirect from the old address so existing links and search rankings carry over.
WordPress tries to redirect old post slugs automatically, but that does not cover every case, such as changes to the whole structure.
Before changing many links, read our guide on changing permalinks without breaking SEO. It explains redirects, internal links and sitemaps.
Once your links are settled, update menus and internal links to point at the final permalinks rather than relying on redirects.
Frequently asked questions
What is the difference between get_permalink and the_permalink?
get_permalink() returns the link as a string, so you can store or change it before output, and it accepts a post ID. the_permalink() prints the link of the current post directly and is meant for use inside the Loop in theme templates.
Why does my new post not show a permalink?
WordPress builds the permalink from the slug, and a brand-new post has no slug until you save a draft or publish. Save the draft, then open the URL panel in the editor sidebar to see the full address.
How do I get the permalink of a category?
In the dashboard, go to Posts, then Categories, hover over the category and click View. In code, use get_category_link() with the category ID, or get_term_link() with the term object or ID.
Can I use the post ID link instead of the permalink?
The plain ID link works and redirects to the permalink, but it is best for quick lookups only. Use the real permalink in menus, posts and shared links so readers and search engines see one consistent address.
How do I get the current page URL in a WordPress template?
On a single post or page, use get_permalink() with get_queried_object_id() to get the current item's link. For archives and other views, use the matching function, such as get_term_link() for a category or tag archive.
Sources
- Customize permalinks WordPress.org
- get_permalink() WordPress Developer Resources
- get_term_link() WordPress Developer Resources
- wp eval WordPress Developer Resources
- URL structure best practices Google Search Central
- URL Inspection tool Google Search Console Help
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
Related guides
About the editors
Researched from the primary sources listed above and checked against our editorial rules before publishing.


