Hi, thanks, I’m glad you enjoy KIA Subtitle. Unfortunately I cannot provide you with that custom code. I don’t know the answer offhand and don’t have the availability to make it a paid project to find out.
I had hoped that
/**
* Translate a %subtitle% slug into actual data.
*
* @param string $request The permalink.
* @param obj WP_Post
* @return string The modified permalink.
*/
function kia_subtitle_permalink( $permalink, $post ) {
if ( function_exists( 'get_the_subtitle' ) && strpos( $permalink, '%subtitle%' ) !== FALSE ) {
// Get the subtitle.
$subtitle = get_the_subtitle( $post->ID );
$subtitle_slug = ( $subtitle != '' ) ? sanitize_title( $subtitle ) : '';
// Replace the tag with the slug.
$permalink = str_replace( '%subtitle%', $subtitle_slug, $permalink );
}
return $permalink;
}
add_filter( 'post_link', 'kia_subtitle_permalink', 10, 2 );
add_filter( 'post_type_link', 'kia_subtitle_permalink', 10, 2 );
Would be enough, but that seems to trick WordPress into looking for an attachment by the name of your subtitle. So you would need to then take a look at altering the request
or pre_get_posts
to have it ignore that subtitle when querying for the appropriate post. I gave it a try, but was unable to resolve it quickly.
Good luck. I’d love if you could post the answer should you find it.