0
0
WordpressHow-ToBeginner · 4 min read

How to Set Permalink in WordPress: Simple Steps

To set a permalink in WordPress, go to the Settings > Permalinks menu in your dashboard and choose a URL structure like Post name. Save changes to apply the new permalink format to your posts and pages.
📐

Syntax

WordPress permalinks use URL structures to define how your post and page links appear. Common structures include:

  • /year/month/day/post-name/ - Shows date and post title
  • /post-name/ - Shows only the post title
  • /category/post-name/ - Shows category and post title

You set these in the WordPress dashboard under Settings > Permalinks.

text
/* Example permalink structures */

// Default (plain)
https://example.com/?p=123

// Day and name
https://example.com/2024/06/15/sample-post/

// Month and name
https://example.com/2024/06/sample-post/

// Numeric
https://example.com/archives/123

// Post name
https://example.com/sample-post/

// Custom structure
https://example.com/%category%/%postname%/
💻

Example

This example shows how to set the permalink to use the Post name structure for clean URLs.

Steps:

  • Log in to your WordPress admin dashboard.
  • Navigate to Settings > Permalinks.
  • Select the Post name option.
  • Click Save Changes.

Now your posts will have URLs like https://example.com/sample-post/.

php
<?php
// This is a WordPress theme function example to flush rewrite rules after permalink change
function my_custom_flush_rewrite_rules() {
    flush_rewrite_rules();
}
add_action('init', 'my_custom_flush_rewrite_rules');
?>
Output
No visible output; permalink rules are refreshed internally.
⚠️

Common Pitfalls

Common mistakes when setting permalinks include:

  • Not saving changes after selecting a new permalink structure.
  • Permalink changes not applying due to missing .htaccess file or incorrect server rewrite rules.
  • Using custom structures with unsupported tags causing 404 errors.
  • Forgetting to flush rewrite rules after programmatic changes.

Always check your server supports URL rewriting (like Apache's mod_rewrite) and that your .htaccess file is writable.

wordpress
/* Wrong: Changing permalink structure but not saving */
// No code, just forgetting to click 'Save Changes' in dashboard

/* Right: Save changes to apply new permalinks */
// Click 'Save Changes' button in Settings > Permalinks
📊

Quick Reference

Tips for setting permalinks:

  • Use Post name for clean, SEO-friendly URLs.
  • Ensure your server supports URL rewriting.
  • Backup your .htaccess file before changes.
  • Flush rewrite rules if changing permalinks programmatically.
  • Test URLs after changes to avoid broken links.

Key Takeaways

Set permalinks in WordPress dashboard under Settings > Permalinks.
Choose a clean structure like Post name for better URLs and SEO.
Always save changes to apply new permalink settings.
Ensure your server supports URL rewriting and .htaccess is writable.
Flush rewrite rules if changing permalinks via code.