0

I have a list of events. I built a CPT “Evenements” for these Events. I included these CPT in my rss feed using the following function

add_filter( 'request', 'wpm_myfeed_request' );  
function wpm_myfeed_request( $qv ) 
{     
    if ( isset( $qv['feed'] ) && !isset( $qv['post_type'] ) ) 
    {       
        // Ici on choisit quels customs posts types seront présents dans le flux RSS        
        $qv['post_type'] = array( 'post', 'Evenements' );   
    }     return $qv;
 }

So, My rss feed is made of a list of CPT. Each entries links to a page as

https://website.de/de/aktivitaeten/firmenbesichtigung/ Where “firmenbesichtigung » is the CPT title.

But I would like all RSS feed entries to link to the page https://website.de/de/aktivitaeten/

not the URL of the specific CPT (https://website.de/de/aktivitaeten/firmenbesichtigung/)

Do you have an idea about this? or How to have all RSS feed entries linking to the same specific page ?

Many many thanks for your help

Timama

2 Answers 2

0

To have all RSS feed entries link to the same specific page, you can modify the permalink for each CPT entry before it is added to the feed.

One way to do this would be to use the post_link filter to modify the permalink for each CPT entry before it is added to the feed.

Here's an example of how you could do this:

add_filter( 'post_link', 'wpm_custom_permalink', 10, 3 );
function wpm_custom_permalink( $permalink, $post, $leavename ) {
    if ( 'Evenements' === $post->post_type ) {
        // Modify the permalink to link to the desired page
        $permalink = 'https://website.de/de/aktivitaeten/';
    }
    return $permalink;
}

This code will modify the permalink for each CPT entry of type Evenements to link to the page

https://website.de/de/aktivitaeten/

Keep in mind that this will change the permalink for the CPT entries themselves, not just the links in the RSS feed. If you only want to modify the links in the RSS feed and not the actual permalinks for the CPT entries, you will need to use a different approach.

One possibility would be to use the the_permalink_rss filter to modify the links in the RSS feed without changing the actual permalinks for the CPT entries.

4
  • oh ! many thanks ! I try it right now and will tell if it is ok !
    – Timama
    Dec 17, 2022 at 15:57
  • You are welcome.
    – Legion
    Dec 17, 2022 at 16:02
  • @Legion the asker does specify RSS so I'd explore the the_permalink_rss option, or, using is_feed() to do this conditionally
    – Tom J Nowell
    Dec 17, 2022 at 16:21
  • You are correct, the the_permalink_rss filter can also be used to modify the link for each custom post type in the RSS feed. I will add another answer.
    – Legion
    Dec 17, 2022 at 16:51
0

Here's an example of how you can use the the_permalink_rss filter to modify the link for each custom post type in the RSS feed:

add_filter( 'the_permalink_rss', 'wpm_modify_rss_link' );
function wpm_modify_rss_link( $link ) {
    if ( get_post_type() == 'Evenements' ) {
        $link = get_site_url() . '/de/aktivitaeten/';
    }
    return $link;
}

This code will filter the link for each custom post type in the RSS feed and set it to the desired URL.

Note: Make sure to replace get_site_url() . '/de/aktivitaeten/' with the actual URL that you want to use for the link.

Using the is_feed() function to conditionally modify the link for custom post types in the RSS feed is also a good approach. You can use the is_feed() function to check if the current request is for an RSS feed, and then modify the link accordingly.

Here's an example of how you can use the is_feed() function to modify the link for each custom post type in the RSS feed:

add_filter( 'the_permalink_rss', 'wpm_modify_rss_link' );
function wpm_modify_rss_link( $link ) {
    if ( is_feed() && get_post_type() == 'Evenements' ) {
        $link = get_site_url() . '/de/aktivitaeten/';
    }
    return $link;
}

This code will only modify the link for custom post types in the RSS feed, and will set the link to the desired URL.

Note: Make sure to replace get_site_url() . '/de/aktivitaeten/' with the actual URL that you want to use for the link.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.