Change the permalink structure and print a post URL
Description: Create a post Permalink practice dated 10 February 2026. Print its URL with the Post name structure. Then change the structure to /%year%/%monthnum%/%postname%/ and print the URL again.
Hint:
wp rewrite structure '/%postname%/'sets the structure.get_permalink( $id )gives the URL of a post.
Solution
$ wp post create –post_title="Permalink practice" –post_status=publish –post_date="2026-02-10 09:00:00" –porcelain
5
$ wp rewrite structure '/%postname%/'
Success: Rewrite structure set.
Success: Rewrite rules flushed.
$ wp eval 'echo get_permalink( 5 );'
http://example.com/permalink-practice/
$ wp rewrite structure '/%year%/%monthnum%/%postname%/'
Success: Rewrite structure set.
Success: Rewrite rules flushed.
$ wp eval 'echo get_permalink( 5 );'
http://example.com/2026/02/permalink-practice/
$ curl -s -o /dev/null -w "%{http_code}\n" http://example.com/2026/02/permalink-practice/
200
How it works
- The structure is saved in the option
permalink_structure. The command also flushes the rewrite rules. - The new URL works at once (code 200). If a URL gives 404 after a change, flush the rules.
Read WordPress Permalinks.
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |