Sitemap CPT URL’s missing date text – year month day
-
I am using the following for our news CPT. The site was redone recently and was using no SEO, sitemaps, and redirects to achieve the, for example, desired URL structure:
/news/2017/09/08/article-name/
So I set up the CPT and below:
Sitewide permalinks are:
/%year%/%monthnum%/%day%/%postname%/
//CPT above register_post_type( 'qa_news', $args ); // Add the permalink structure we want: add_permastruct( 'qa_news', '/news/%year%/%monthnum%/%day%/%name%/', false ); // Matching nice URLs to the URLs WP will use to get news(s)... // All news from one day: add_rewrite_rule( '^news/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})(/page/([0-9]+))?/?$', 'index.php?post_type=qa_news&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[5]', 'top' ); // An individual news article: add_rewrite_rule( '^news/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/?$', 'index.php?post_type=qa_news&name=$matches[4]', 'top' ); // All news from one month: add_rewrite_rule( '^news/([0-9]{4})/([0-9]{1,2})(/page/([0-9]+))?/?$', 'index.php?post_type=qa_news&year=$matches[1]&monthnum=$matches[2]&paged=$matches[4]', 'top' ); // All news from one year: add_rewrite_rule( '^news/([0-9]{4})(/page/([0-9]+))?/?$', 'index.php?post_type=qa_news&year=$matches[1]&paged=$matches[3]', 'top' ); } // Hook into the 'init' action add_action( 'init', 'news_post_type', 0 ); /** * Have our custom post type, News, use the nice permalinks we wanted. * Should tie in with the add_permastruct() we used when creating the post * type. */ function qa_news_permalinks( $url, $post ) { if ( 'qa_news' == get_post_type( $post ) ) { $url = str_replace( "%year%", get_the_date('Y'), $url ); $url = str_replace( "%monthnum%", get_the_date('m'), $url ); $url = str_replace( "%day%", get_the_date('d'), $url ); $url = str_replace( "%name%", $post->post_name, $url ); } return $url; } add_filter( 'post_type_link', 'qa_news_permalinks', 10, 2 );
It is definitely working, The only issue is we are getting a whacked News CPT sitemap index.
example:
site.com/news////article-name/
(the year, month, date text are missing!)
And the large search engine is complaining as it should since we just submitted the sitemap last week and these URL’s have been added to the index..
This most likely related to Yoast (non-Pro version) topic has been open for a very long time:
https://www.ads-software.com/support/topic/custom-post-type-slug-rewrite-not-recognized-by-yoast/
I have found no resolution and it does not look like Yoast can/will help in their support forum here?
Anyone come across this and have a resolution that is tested and working today? Any thoughts?
Thanks in advance!
The page I need help with: [log in to see the link]
- The topic ‘Sitemap CPT URL’s missing date text – year month day’ is closed to new replies.