I need to access a page which is name 2011.
The trouble is that WP thinks that I am trying to read the 2011 posts of my blog.
The only way I can make it work for the moment, is to change the permalink of my 2011 page to be mypage-2011.
Is there anyway I can make/force WP to use 2011 as permalink for the page 2011, so it can be viewed via www.site.com/2011
thx
s
First of all rewrite handling can become very complicated very quickly – particularly when your desired structure conflicts with WordPress’ default behaviour. The best advice is probably to just avoid such conflicts rather than try to resolve them. With that as a premable…
WordPress generates rewrite rules from various sources: from registered post types, rules that plug-ins manually add and also ‘tags’ (default / plug-in added). Tags are the
%year%
,%author%
etc that you can use in your custom permalink structure. It also has rewrite rules that it automatically generates: These include date structures (see source). e.g.These rules are more specific than page rules, since they only apply to (in regex)
([0-9]{4})
– that is 4 digit numbers like 2012. (The second rule only applies to([0-9]{4})/([0-9]{2})
e.g. 2012/05.There are two solutions to this:
%year%
tagChange rule for the %year% tag
As mentioned above, the
%year%
tag expects a 4-digit number – and the corresponding rule only appears when this is met. You can change this rule so it only matchesdate/([0-9]{4})
– that is, it matchesdate/[four-digit-number]
. To do that:Warning: This means whenever the
%year%
tag is used (say in your custom permalink structure) – the year in the permalink must be preceded bydate/
. Notable changes includeno longer points to May 2012 archives. Instead you must use:
(similarly for the date archive).
For this reason, you might prefer to use method 2.
Change the date rewrite rules
When the date rewrite rules are being generated they are filtered (see source) using the
date_rewrite_rules
filters.More specifically an array of the form
regex=>query
is filtered. An array where the key is a regular expression, and the value is how it is interpreted as a query). E.g.:It’s this last rule that is causing the problem. So you can remove it, and then add a replacement (if desired):
Now
goes to your page. And
points to the year archives. While the month archives remain unchanged. e.g.:
still points to May 2012 archive.
Warning: Clearly you can see another conflict arising if your 2012 page has a sub-page called ’05’. Similar problems will occur if you use ‘page’, ‘feed’, ‘atom’ etc (see rewrite rules above). This method would require you to manually remove/replace each of the rules that need altering. This can get messy quickly – which is why its best just to avoid using these as page names.
Summary
First of all: any changes won’t take effect until you flush the rewrite rules. Do this (only) by going to Settings > Permalinks and clicking save.
Method 2 is probably preferable – given that method 1 may do ‘too much’. However, method 2 is a bit ‘dirtier’ – you’re ‘fine tuning’ the date permastructure and you may find that you need to tune it further.
For instance, using method 2, if your 2012 page had a sub-page 05 – it’s permalink would be be interpreted as the May 2012 archive. You would then need to alter the rewrite-rules for month archives. Going three-levels deep, with a page called ’01’ you will get the 1st May 2012 archive. At each level you also have problems if you have pages called ‘page’, or ‘feed’ and such. As mentioned, its probably best to try and avoid such names.