I want to redirect my blog articles, for example,
http://www.example.com/blog/2014/september/03/post-name
But in wordpress it only allows me to use the month number,
http://www.example.com/blog/2014/09/03/post-name .
I am looking for this, but have not found anything useful. Some unanswered posts, and they donβt even say whether this is possible or not. Even Wordpress docs have no references to this. I found the following code, but it changes the url but does not bind the mail page.
<?php class MonthName { public static $monthnames = array( 'january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december', ); public static $monthcodes = array( 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec', ); public static function init() { add_rewrite_tag( '%monthname%', '(' . implode('|', self::$monthnames) . ')' ); add_rewrite_tag( '%monthcode%', '(' . implode('|', self::$monthcodes) . ')' ); add_rewrite_rule( '^([0-9]{4})-(' . implode( '|', self::$monthnames ) . ')/([0-9]+)/?', 'index.php?p=$matches[3]', 'top' ); add_rewrite_rule( '^([0-9]{4})-(' . implode( '|', self::$monthcodes ) . ')/([0-9]+)/?', 'index.php?p=$matches[3]', 'top' ); } public static function filter_post_link( $permalink, $post ) { if ( false === strpos( $permalink, '%monthname%' ) && false === strpos( $permalink, '%monthcode%' ) ) { return $permalink; } try { $monthindex = intval(get_post_time( 'n', "GMT" == false, $post->ID )); $monthname = self::$monthnames[$monthindex - 1]; $monthcode = self::$monthcodes[$monthindex - 1]; $permalink = str_replace( '%monthname%', $monthname, $permalink ); $permalink = str_replace( '%monthcode%', $monthcode, $permalink ); return $permalink; } catch (Exception $e) { return $permalink; } } } add_action( 'init', array( 'MonthName', 'init' ) ); add_filter( 'post_link', array( 'MonthName', 'filter_post_link' ), 10, 2 );
Someone will say if this is possible or not. If possible, you can tell how to solve this problem.