URL Routing
The Controller/Router.php class implements Magento\Framework\App\RouterInterface and intercepts all requests matching the configured blog base path.
Route Resolution Order
The router tries each pattern in order. The first match wins.
| Pattern | Example URL | Controller | Action | Params |
|---|---|---|---|---|
| Blog listing | / | blog | index | - |
| Paginated listing | / | blog | index | page=2 |
| Category archive | / | category | view | slug=news |
| Category paginated | / | category | view | slug=news, page=2 |
| Tag archive | / | tag | view | slug=magento |
| Author archive | / | author | view | slug=john |
| Search | / | search | results | (query via GET) |
| Single post | / | post | view | slug=my-post-slug |
The single-post catch-all pattern is always last. It matches any single path segment that does not match a more specific pattern above.
How the Router Works
public function match(RequestInterface $request): ?ActionInterface
{
// 1. Check module is configured (URL + API key set)
if (!$this->config->isConfigured()) {
return null;
}
// 2. Check URL starts with blog base path
$identifier = trim($request->getPathInfo(), '/');
$basePath = $this->config->getBlogBaseUrl();
if (!str_starts_with($identifier, $basePath)) {
return null;
}
// 3. Resolve the remaining path segment
$path = substr($identifier, strlen($basePath) + 1);
$result = $this->resolveRoute($path);
// 4. Set request params and dispatch
$request->setModuleName('wordpress');
$request->setRouteName('wordpress');
$request->setControllerName($result['controller']);
$request->setActionName($result['action']);
// ...
} The router sets the route name to wordpress, the frontend route ID in etc/frontend/routes.xml. Magento builds the page’s full action name and default layout handle from it, for example wordpress_blog_index. On 2.0.4 and earlier the route name was empty, which gave handles like _blog_index. Magento’s ESI controller rejects those, so with Varnish the store’s top menu rendered empty on cached blog pages.
The blog controllers extend Magento\Framework\App\Action\Action and implement HttpGetActionInterface. Magento sets the store and currency context in plugins on AbstractAction, so a controller that only implements ActionInterface would serve every store view with the default store’s cache variation.
Configurable Base Path
The base path is read from ocmlabs_wordpress/blog/base_url in Magento system config. It defaults to blog but can be changed to any alphanumeric string (e.g., news, articles, journal).
If you change the base path, flush the Magento cache. Any hardcoded links in content must also be updated (or rely on the link rewriting in ContentProcessor).
Router sortOrder
The WordPress router runs at sortOrder 25 in Magento’s router list. The standard Magento router list order is:
| sortOrder | Router |
|---|---|
| 10 | Admin |
| 20 | Robots/Sitemap |
| 25 | WordPress (this module) |
| 30 | Standard Magento URL rewrites |
| 100 | CMS |
| 200 | Default (404) |