|
1 | | -# Knowledge Base Permalinks Tutorial |
| 1 | +# Knowledge Base Permalinks |
2 | 2 |
|
3 | | -This guide explains how permalinks work in the WebberZone Knowledge Base plugin and how to customise them in both the free and Pro versions. Follow the sections below to configure URLs, understand placeholder behaviour, and troubleshoot issues. |
| 3 | +This guide explains how Knowledge Base handles URLs and how to configure custom permalink structures in [Pro](https://webberzone.com/plugins/knowledgebase/). |
4 | 4 |
|
5 | | -## 1. Permalink Settings Overview |
| 5 | +## Quick start |
6 | 6 |
|
7 | | -All permalink settings are located in **Knowledge Base → Settings → General** under the **Permalinks** section. The Setup Wizard also exposes these fields during onboarding. |
| 7 | +- **Free version**: Set your slugs in **Knowledge Base → Settings → Permalinks** |
| 8 | +- **Pro version**: Enable **custom permalinks** and use placeholders like `%product_name%` or `%section_name%` in your article structure |
8 | 9 |
|
9 | | -### 1.1 Available Settings |
| 10 | +## Permalink settings |
10 | 11 |
|
11 | | -- **Knowledge Base slug** (`kb_slug`): Sets the base path for the Knowledge Base post type. Default: `knowledgebase`. Used in free version and as fallback in Pro. |
12 | | -- **Product slug** (`product_slug`): Base path for product archives. Default: `kb/product`. Supports placeholders in Pro (e.g., `support/product`). |
13 | | -- **Section slug** (`category_slug`): Base path for section archives. Default: `kb/section`. Supports placeholders in Pro (e.g., `support/product/%product_name%/%section_name%`). |
14 | | -- **Tags slug** (`tag_slug`): Base path for tag archives. Default: `kb/tags`. Supports placeholders in Pro (e.g., `support/tag`). |
15 | | -- **Article Permalink Structure** (`article_permalink`): Custom structure for article URLs. **Pro feature only**. Default: empty (uses `{kb_slug}/%postname%`). |
| 12 | +All permalink settings are located in **Knowledge Base → Settings → General** under the **Permalinks** section. |
16 | 13 |
|
17 | | -### 1.2 Free Version Behavior |
| 14 | +### Available settings |
18 | 15 |
|
19 | | -- Free version uses standard WordPress permastruct rewrite rules for all taxonomies. |
20 | | -- Article URLs follow the pattern: `{kb_slug}/%postname%` |
21 | | -- Example: If `kb_slug` is `knowledgebase`, articles appear at `/knowledgebase/article-name/` |
22 | | -- Taxonomy slugs can be customized but do not support placeholders. |
23 | | -- To use placeholders and custom article structures, upgrade to Pro. |
| 16 | +- **Knowledge Base slug** (`kb_slug`): Sets the base path for the Knowledge Base. Default: `knowledgebase` |
| 17 | +- **Product slug** (`product_slug`): Base path for product archives. Default: `kb/product` |
| 18 | +- **Section slug** (`category_slug`): Base path for section archives. Default: `kb/section` |
| 19 | +- **Tags slug** (`tag_slug`): Base path for tag archives. Default: `kb/tags` |
| 20 | +- **Article Permalink Structure** (`article_permalink`): Custom structure for articles. **Pro feature only** |
24 | 21 |
|
25 | | -## 2. Pro: Custom Permalinks Engine |
| 22 | +## Pro: custom permalinks engine |
26 | 23 |
|
27 | | -The Pro module activates custom permalink handling when: |
| 24 | +Pro adds a custom permalinks engine that lets you control your URL structure using placeholders. |
28 | 25 |
|
29 | | -- A custom `article_permalink` structure is set (with or without placeholders) |
30 | | -- Taxonomy slugs include placeholders (e.g., `support/product/%product_name%/%section_name%`) |
| 26 | +**When this activates:** |
31 | 27 |
|
32 | | -### 2.1 Supported Placeholders |
| 28 | +- Pro is installed and activated |
| 29 | +- You enter a custom structure in the article permalink field (anything other than the default `%postname%`) |
33 | 30 |
|
34 | | -```text |
35 | | -%product_name% %section_name% %section_id% |
36 | | -%tag_name% %post_id% %postname% %author% |
37 | | -``` |
38 | | - |
39 | | -These map to query variables used when building rewrite rules and are sanitised before use. |
40 | | - |
41 | | -Placeholders can be filtered with `wzkb_custom_permalink_placeholders`, allowing developers to register additional tokens. |
42 | | - |
43 | | -### 2.2 How Custom Permalinks Work |
44 | | - |
45 | | -The Pro version automatically builds your article and taxonomy URLs based on the structures you define: |
46 | | - |
47 | | -1. **Rewrite rules are generated** - Custom rewrite rules are created for articles, products, sections, and tags based on your structures. |
48 | | -2. **Placeholders get replaced** - Each placeholder like `%product_name%` or `%section_name%` is replaced with the actual product or section assigned to that article. |
49 | | -3. **URLs are built automatically** - The plugin combines your custom structure with the replaced placeholders to create the final URL. |
50 | | -4. **Smart conflict handling** - When multiple structures share the same base path (e.g., article and section structures both starting with `support/product/`), the plugin prioritizes article rules to prevent misrouting. |
51 | | -5. **Permastruct is disabled** - When custom structures are used, WordPress's default taxonomy permastruct rules are disabled to avoid conflicts. Custom rewrite rules handle all routing instead. |
52 | | - |
53 | | -**Example:** If you set: |
54 | | - |
55 | | -- `kb_slug`: `support/knowledgebase` |
56 | | -- `article_permalink`: `support/product/%product_name%/%section_name%/%postname%` |
57 | | - |
58 | | -And create an article titled "Installation Guide" in the "Getting Started" section of the "Widget Suite" product, the URL becomes: |
59 | | -`/support/product/widget-suite/getting-started/installation-guide/` |
60 | | - |
61 | | -### 2.3 What Each Placeholder Does |
62 | | - |
63 | | -- **%product_name%** - Replaced with the product slug (e.g., `widget-suite`) |
64 | | -- **%section_name%** - Replaced with the section slug (e.g., `getting-started`) |
65 | | -- **%section_id%** - Replaced with the section ID number (e.g., `42`) |
66 | | -- **%tag_name%** - Replaced with the tag slug (e.g., `troubleshooting`) |
67 | | -- **%postname%** - Replaced with the article slug (e.g., `installation-guide`) |
68 | | -- **%post_id%** - Replaced with the article ID number (e.g., `123`) |
69 | | -- **%author%** - Replaced with the author username (e.g., `john-smith`) |
70 | | - |
71 | | -**Tip:** Hierarchical placeholders like `%section_name%` can include parent sections, creating nested URLs like `/parent-section/child-section/`. |
| 31 | +**Supported placeholders:** |
72 | 32 |
|
73 | | -## 3. Building Custom Structures |
| 33 | +- `%product_name%` — The product slug (from your Products taxonomy) |
| 34 | +- `%section_name%` — The top-level section slug for articles |
| 35 | +- `%postname%` — The article slug |
| 36 | +- `%post_id%` — The article ID |
| 37 | +- `%author%` — The author username |
74 | 38 |
|
75 | | -### 3.1 Example: Custom Prefix with Product → Section → Article |
| 39 | +**How custom permalinks work:** |
76 | 40 |
|
77 | | -```text |
78 | | -kb_slug: support/knowledgebase |
79 | | -product_slug: support/product |
80 | | -category_slug: support/product/%product_name%/%section_name% |
81 | | -article_permalink: support/product/%product_name%/%section_name%/%postname% |
82 | | -``` |
83 | | - |
84 | | -- Produces article URLs like `/support/product/widget-suite/getting-started/installing-widget-suite/` |
85 | | -- Produces section URLs like `/support/product/widget-suite/getting-started/` |
86 | | -- Produces product URLs like `/support/product/widget-suite/` |
87 | | -- Custom prefix `support/` is shared across all structures to avoid KB slug prepending |
88 | | -- Requires each article to have a product and section assigned; otherwise the placeholder resolves to an empty segment |
89 | | - |
90 | | -### 3.2 Example: Simple Structures Without Placeholders |
91 | | - |
92 | | -```text |
93 | | -kb_slug: knowledgebase |
94 | | -product_slug: kb/product |
95 | | -category_slug: kb/section |
96 | | -tag_slug: kb/tags |
97 | | -article_permalink: %product_name%/%section_name%/%postname% |
98 | | -``` |
| 41 | +1. You define a structure using placeholders |
| 42 | +2. Pro generates the appropriate rewrite rules |
| 43 | +3. Articles use your custom structure |
| 44 | +4. Taxonomy archives (products, sections, tags) use their configured slugs |
99 | 45 |
|
100 | | -- Product URLs: `/kb/product/widget-suite/` (term name appended automatically) |
101 | | -- Section URLs: `/kb/section/getting-started/` (term name appended automatically) |
102 | | -- Tag URLs: `/kb/tags/troubleshooting/` (term name appended automatically) |
103 | | -- Article URLs: `/knowledgebase/widget-suite/getting-started/installing-widget-suite/` |
| 46 | +**Example:** |
104 | 47 |
|
105 | | -### 3.3 Example: Numeric Identifiers |
| 48 | +Set `kb_slug` to `help` and `article_permalink` to: |
106 | 49 |
|
107 | 50 | ```text |
108 | | -article_permalink: %section_id%/%post_id%/%postname% |
| 51 | +%product_name%/%section_name%/%postname% |
109 | 52 | ``` |
110 | 53 |
|
111 | | -- Helpful for legacy systems needing numeric identifiers in the URL |
112 | | -- Produces URLs like `/42/123/article-slug/` |
113 | | -- Rewrite tags for `section_id` and `post_id` are registered automatically |
114 | | - |
115 | | -### 3.4 Term Archive Structures with Placeholders |
116 | | - |
117 | | -- **Sections with product context**: `category_slug` set to `support/product/%product_name%/%section_name%` nests sections under their products |
118 | | -- **Tags with section context**: `tag_slug` set to `support/product/%product_name%/%section_name%/%tag_name%` provides full context |
119 | | -- When taxonomy slugs include placeholders, custom rewrite rules are generated to handle the dynamic segments |
120 | | - |
121 | | -## 4. Configuration Workflow |
122 | | - |
123 | | -1. **Plan taxonomy usage**: Decide which placeholders are meaningful for your data hierarchy. |
124 | | -2. **Update Knowledge Base → Settings → General → Permalinks** with desired structures. |
125 | | -3. **Save settings** to trigger rewrite rule regeneration (automatic in setup and admin UI). |
126 | | -4. **Flush rewrite rules**: Visit **Settings → Permalinks** and click **Save Changes** to ensure WordPress recognizes the new rules. |
127 | | -5. **Assign terms** consistently (products, sections, tags) so placeholders resolve correctly. |
128 | | -6. **Test URLs**: |
129 | | - - Visit an article, product, section, and tag page. |
130 | | - - Verify the URL matches your configured structure. |
131 | | - - Use the WordPress Rewrite Rules Inspector or `wp rewrite list` CLI if needed. |
132 | | - |
133 | | -## 5. How Pro Handles Custom Structures |
134 | | - |
135 | | -### 5.1 Rewrite Rule Generation |
| 54 | +Result: `https://example.com/help/wordpress/getting-started/` |
136 | 55 |
|
137 | | -When Pro is enabled and custom structures are detected: |
| 56 | +**Note:** `%section_name%` for articles always returns the top-level parent slug, not the full hierarchy. |
138 | 57 |
|
139 | | -1. **Custom rewrite rules are created** for articles, products, sections, and tags based on your configured structures |
140 | | -2. **Taxonomy permastruct is disabled** to prevent conflicts with custom rules |
141 | | -3. **Article rules are prioritized** to ensure article URLs are matched before product/section archives |
142 | | -4. **Child section rules are conditionally disabled** when article structures have more segments than section structures, preventing misrouting |
| 58 | +## Configuration workflow |
143 | 59 |
|
144 | | -### 5.2 Permalink Generation |
| 60 | +1. Open Knowledge Base → Settings → General |
| 61 | +2. Configure your base slugs (kb_slug, product_slug, etc.) |
| 62 | +3. Pro users: set your custom article permalink structure |
| 63 | +4. Save changes |
145 | 64 |
|
146 | | -When generating permalinks for articles and taxonomies: |
| 65 | +> **Important:** After changing permalink settings, visit Settings → Permalinks in WordPress to flush your rewrite rules. This prevents 404 errors. |
147 | 66 |
|
148 | | -1. **Placeholders are replaced** with actual term/post values |
149 | | -2. **Term slugs are appended** automatically for taxonomy structures without explicit placeholders |
150 | | -3. **KB slug is intelligently prepended** only when the custom structure doesn't already start with the KB slug's first segment |
151 | | -4. **Final URL is constructed** and returned via `get_term_link()` and `get_permalink()` filters |
| 67 | +## Troubleshooting |
152 | 68 |
|
153 | | -### 5.3 Fallback Behavior Without Pro |
| 69 | +### 404 errors after changing settings |
154 | 70 |
|
155 | | -If Pro is not enabled but custom structures are configured: |
| 71 | +Visit Settings → Permalinks in WordPress to flush your rewrite rules. |
156 | 72 |
|
157 | | -- **Permastruct rewrite rules remain active** to ensure URLs work |
158 | | -- **Custom article structures are ignored** and default `{kb_slug}/%postname%` is used |
159 | | -- **Taxonomy slugs work** but placeholders are not supported |
160 | | -- **No custom rewrite rules are generated** - WordPress handles routing via permastruct |
| 73 | +### URLs not matching your structure |
161 | 74 |
|
162 | | -## 6. Developer Hooks & Extensibility |
| 75 | +- Check you've entered a custom structure (not just `%postname%`) |
| 76 | +- Ensure Pro is active |
| 77 | +- Verify your placeholder syntax |
163 | 78 |
|
164 | | -- `wzkb_custom_permalink_placeholders`: Register extra placeholders or override default mappings. |
165 | | -- `wzkb_article_permalink_structure` and `wzkb_term_permalink_structure`: Filter the resolved path before it is prefixed with the KB slug. |
166 | | -- `wzkb_after_setting_output`: Used by Pro to inject placeholder documentation beneath the settings header for admins. |
| 79 | +### Conflicts with other plugins |
167 | 80 |
|
168 | | -## 7. Troubleshooting Tips |
| 81 | +Some SEO plugins modify rewrite rules. If you experience conflicts: |
169 | 82 |
|
170 | | -- **404 errors**: Visit **Settings → Permalinks** and click **Save Changes** to flush rewrite rules. This is the most common fix. |
171 | | -- **Empty placeholders**: Ensure articles have the required product/section/tag assignments. Missing assignments result in empty URL segments. |
172 | | -- **Wrong content loading**: If an article URL loads a product/section archive instead, flush rewrite rules. Pro prioritizes article rules, but rule order depends on proper flushing. |
173 | | -- **Conflicting slugs**: Avoid reusing the KB slug for other pages. Pro attempts to resolve clashes by detecting shared prefixes, but unique slugs prevent ambiguity. |
174 | | -- **Taxonomy URLs not working**: If product/section/tag URLs return 404, ensure their slugs are configured in settings and rewrite rules are flushed. |
175 | | -- **Testing root-level URLs**: When using `%postname%` without a prefix, verify that article slugs do not collide with regular posts or pages. |
176 | | -- **Pro not enabled**: Custom article structures are ignored if Pro is not active. Free version uses default `{kb_slug}/%postname%` structure. |
| 83 | +- Test with other plugins disabled |
| 84 | +- Check your rewrite rules using a plugin like [Rewrite Rules Inspector](https://wordpress.org/plugins/rewrite-rules-inspector/) |
| 85 | +- Priority is given to articles over taxonomy archives to prevent conflicts |
177 | 86 |
|
178 | | -## 8. Summary |
| 87 | +## Summary |
179 | 88 |
|
180 | | -- **Free version** supports basic slug customization for taxonomies and default article URLs using the KB slug. |
181 | | -- **Pro version** unlocks placeholder-driven structures for articles and taxonomies with intelligent rewrite rule generation and conflict resolution. |
182 | | -- **Custom prefixes** (e.g., `support/product/`) allow you to organize URLs outside the KB slug hierarchy. |
183 | | -- **Consistent taxonomy assignments** and thoughtful structure planning ensure clean, SEO-friendly URLs tailored to your knowledge base. |
184 | | -- **Rewrite rule flushing** is essential after any permalink setting changes to ensure WordPress recognizes the new URL patterns. |
| 89 | +- Free version: configure base slugs for articles and taxonomies |
| 90 | +- Pro version: build custom URL structures using placeholders |
| 91 | +- Always flush rewrite rules after changing permalink settings |
| 92 | +- Pro handles smart conflict resolution between articles and taxonomies |
0 commit comments