I have a function that rewrites the URL before post slug including a custom taxonomy

function wpa_show_permalinks( $post_link, $post ){
if ( is_object( $post ) && $post->post_type == 'aktuelles' ){
    $terms = wp_get_object_terms( $post->ID, 'nachrichtenkategorie' );
    if( $terms ){
        return str_replace( '%nachrichtenkategorie%' , $terms[0]->slug , $post_link );
    }
}
return $post_link;
}

add_filter( 'post_type_link', 'wpa_show_permalinks', 1, 2 );

The function works just fine and replaces %nachrichtenkategorie% in URL when accessing from the archive

Getting the permalink of a post with get_permalink(123) doesn’t replace the %nachrichtenkategorie% in the url therefore…


This is only a snippet of a WordPress Website Design Article written by Razvan Cuceu

Read Full Article


Content Disclaimer 

This Content is Generated from RSS Feeds, if your content is featured and you would like to be removed, please Contact Us With your website address and name of site you wish to be removed from.

Note:

You can control what content is distributed in your RSS Feed by using your Website Editor.

Tech Shop Offers