Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Customizing Permalink Structure in WordPress
📖 Scenario: You are building a blog website using WordPress. You want to make your post URLs easy to read and remember by customizing the permalink structure.
🎯 Goal: Learn how to set up a custom permalink structure in WordPress to improve URL readability and SEO.
📋 What You'll Learn
Create a variable to hold the default permalink structure string
Add a variable to hold the new custom permalink structure string
Use the WordPress function update_option to set the new permalink structure
Flush rewrite rules using flush_rewrite_rules to apply changes
💡 Why This Matters
🌍 Real World
Customizing permalinks helps make website URLs user-friendly and better for search engines.
💼 Career
WordPress developers often need to configure permalinks for client websites to improve usability and SEO.
Progress0 / 4 steps
1
Set the default permalink structure
Create a variable called default_permalink and set it to the string '/archives/%post_id%' which represents the default permalink structure.
Wordpress
Hint
The default permalink structure uses the post ID inside the URL after '/archives/'.
2
Define a new custom permalink structure
Create a variable called custom_permalink and set it to the string '/%category%/%postname%/' which will show category and post name in URLs.
Wordpress
Hint
The new permalink structure includes the category and post name for better readability.
3
Update WordPress permalink option
Use the WordPress function update_option with the first argument 'permalink_structure' and the second argument custom_permalink to update the permalink setting.
Wordpress
Hint
This function changes the permalink structure setting in WordPress.
4
Flush rewrite rules to apply changes
Call the WordPress function flush_rewrite_rules with no arguments to refresh the permalink rules and apply the new structure.
Wordpress
Hint
This function refreshes WordPress's URL rules so the new permalink structure works immediately.
Practice
(1/5)
1. What does the %postname% tag represent in a WordPress permalink structure?
easy
A. The date the post was published
B. The slug of the post or page
C. The category of the post
D. The author of the post
Solution
Step 1: Understand the purpose of %postname%
The %postname% tag is used to insert the post slug, which is a URL-friendly version of the post title.
Step 2: Compare with other tags
Other tags like %year% or %category% represent date or category, not the post slug.
Final Answer:
The slug of the post or page -> Option B
Quick Check:
%postname% = post slug [OK]
Hint: Remember postname means the post's URL-friendly title [OK]
Common Mistakes:
Confusing %postname% with %category%
Thinking %postname% shows the date
Assuming %postname% is the author name
2. Which of the following is a valid custom permalink structure in WordPress?
easy
A. /%day%/%month%/%slug%/
B. /post/%author%/%date%/
C. /%year%/%monthnum%/%postname%/
D. /%category%/%postid%/%title%/
Solution
Step 1: Check valid WordPress tags
WordPress supports tags like %year%, %monthnum%, and %postname%. /%year%/%monthnum%/%postname%/ uses only valid tags.
Step 2: Identify invalid tags in other options
Options A, B, and C use invalid tags like %date%, %title%, or %slug% which are not recognized by WordPress.
Final Answer:
/%year%/%monthnum%/%postname%/ -> Option C
Quick Check:
Valid tags only = /%year%/%monthnum%/%postname%/ [OK]
Hint: Use only official WordPress tags in permalinks [OK]
Common Mistakes:
Using tags like %title% or %slug% which don't exist
Mixing date formats incorrectly
Forgetting trailing slash in structure
3. Given the permalink structure /%category%/%postname%/, what would be the URL for a post titled "Summer Tips" in the "Travel" category?
medium
A. /travel/summer-tips/
B. /summer-tips/travel/
C. /category/travel/summer-tips/
D. /travel/category/summer-tips/
Solution
Step 1: Understand the structure tags
The structure /%category%/%postname%/ means the URL starts with the category slug, then the post slug.
Step 2: Apply to given post and category
Category "Travel" becomes "travel" and post "Summer Tips" becomes "summer-tips". So URL is /travel/summer-tips/.
Final Answer:
/travel/summer-tips/ -> Option A
Quick Check:
Category + postname = /travel/summer-tips/ [OK]
Hint: Category comes first, then postname in this structure [OK]
Common Mistakes:
Swapping category and postname order
Adding extra words like 'category' in URL
Using capital letters in URL slugs
4. A WordPress site uses the permalink structure /%year%/%postname%/. After changing it to /%postname%/, some old links show 404 errors. What is the likely cause?
medium
A. The .htaccess file was not updated to reflect the new structure
B. The post slugs were deleted accidentally
C. The site URL was changed in settings
D. The category base was not set correctly
Solution
Step 1: Understand permalink changes effect
Changing permalink structure requires updating rewrite rules in the .htaccess file for URLs to work correctly.
Step 2: Identify cause of 404 errors
If .htaccess is not updated, old URLs won't redirect properly, causing 404 errors.
Final Answer:
The .htaccess file was not updated to reflect the new structure -> Option A
Quick Check:
Rewrite rules update needed = The .htaccess file was not updated to reflect the new structure [OK]
Hint: Always update .htaccess after changing permalinks [OK]
Common Mistakes:
Assuming post slugs were deleted
Ignoring .htaccess rewrite rules
Confusing category base with permalink structure
5. You want your WordPress URLs to show the year, category, and post name, but avoid duplicate URLs for posts in multiple categories. Which permalink structure helps prevent duplicates?
hard
A. /%year%/%category%/%postname%/
B. /%category%/%postname%/
C. /%postname%/
D. /%year%/%postname%/
Solution
Step 1: Understand duplicate URL issue
Using %category% can cause multiple URLs if a post belongs to multiple categories.
Step 2: Choose structure avoiding category
Removing %category% from the URL avoids duplicates. Including %year% and %postname% keeps URLs informative.
Final Answer:
/%year%/%postname%/ -> Option D
Quick Check:
Exclude category to prevent duplicates = /%year%/%postname%/ [OK]
Hint: Avoid %category% in URLs to stop duplicates [OK]