I used add_rewrite_endpoint to add a string at the end of url.

function wpseo331941_reader_endpoint() {
    add_rewrite_endpoint('readers', EP_PERMALINK | EP_PAGES);
add_action('init', 'wpseo331941_reader_endpoint', 10, 0);

So now my posts have two urls (http://example.com/article/post-title-here/ and http://example.com/article/post-title-here/readers/).

I'm using yoast plugin to add my custom posts links in the sitemap file.
How can I tell yoast for a specific custom post type to add the new format of url http://example.com/article/post-title-here/readers/ in addition to the original already added one http://example.com/article/post-title-here/?

I can use filter wpseo_xml_sitemap_post_url to change the url and add readers/ at the end of it,

function filter_wpseo_xml_sitemap_post_url( $get_permalink, $post ) { 
    if($post->post_type == 'article'){
        return $get_permalink . 'readers/';
    return $get_permalink; 
add_filter( 'wpseo_xml_sitemap_post_url', 'filter_wpseo_xml_sitemap_post_url', 10, 2 );

But this removes/replaces the old url format http://example.com/article/post-title-here/, but what I need is to keep both urls in the sitemap file.

  • What about asking it at the forum where your question belongs? Yoast – Charles Mar 22 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.