This site has been very helpful for me in learning how to rewrite permalinks using add_filters to solve issues we were having when we merged two blogs into one. But, I do have one item I have been unable to find any tips for:
On the date based archives links, i.e. www.domain.com/2011/12/
I simply want to translate them to: www.domain.com/news/2011/12/
Thanks in advance for any assistance.
The really easy way: Change your permalink structure to include a “front” part. Eg.
/news/%postname%
The slightly more complicated and inflexible way: WordPress holds it’s data permastruct in a property of the global
WP_Rewrite
object stored in$wp_rewrite
. You can hook in sometime early-ish (aroundinit
) and change this.Inflexible because you’ve hard-coded the date base (
news
). This works fine, and if you don’t need the flexibility and want a quick fix, you should do this. Just be sure to flush your rewrite rules: visit Settings > Permalinks and hit save.The totally awesome, but a little bit complex way: Add a field to the permalinks options page where you can specify the date base.
A class to wrap things up in.
Now we need to hook into
admin_init
and use the settings API to add our field to the “Optional” section. We only need to useadd_settings_field
because Permalink options doesn’t actually use the settings API.We also need to hook into
load-options-permalink.php
to save stuff (due to the lack of settings API support).And finally hook into
init
and change the data permastruct. We can piggy-back on some build in validation that WordPress does by usingWP_Rewrite::get_date_permastruct
. Then it’s just a matter of some regex replacement.Here is the third option wrapped up in a plugin.
sounds like you need to rewrite the custom post type permalink or in this case the permastruct.
I didn’t have time to test but did you try with this plugin? http://wordpress.org/extend/plugins/custom-post-permalinks/
Looks like you can edit the permalink by adding /%year%/%monthnum%/ to the post type?
Also you can take a look at the Codex here
http://codex.wordpress.org/Function_Reference/register_post_type
I hope it helps.