• Hi, love your plugin! I currently use it for my Products. I would like to add the Subtitle content to the permalink, so that the auto generated permalink includes both the product title and the subtitle. I’m not too picky about the format it appears as, so long as it’s there. Could you provide me with the code to do this please?

Viewing 1 replies (of 1 total)
  • Plugin Author HelgaTheViking

    (@helgatheviking)

    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.

Viewing 1 replies (of 1 total)
  • The topic ‘Add Subtitle to Permalink’ is closed to new replies.