How to add parent slug to CPT URL

If you need to add a second root parent slug to your Custom Post Type, you can do it using the below code snippet.
This will add the word "resources" to the URL so "/places/" will become "/resources/places/".

function gd_snippet_option_post_types( $value, $key, $default ) {
	$post_type 	= 'gd_place'; // Post type
	$top_level_item = 'resources'; // Top level item

	if ( ! empty( $value[ $post_type ] ) ) {
		$value[ $post_type ]['has_archive'] 	= $top_level_item . '/' . $value[ $post_type ]['rewrite']['slug'];
		$value[ $post_type ]['rewrite']['slug'] = $top_level_item . '/' . $value[ $post_type ]['rewrite']['slug'];
	}

	return $value;
}
add_filter( 'geodir_get_option_post_types', 'gd_snippet_option_post_types', 21, 3 );<br>
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us