This snippet shows how to use the override_child_permalink action.
Enable the “Use Parent Permalink” Broadcast setting for this action to be called at all.
/**
@brief Example showing how to only show the parent permalink for the "page" and "documentation" post types.
@details For all other post types, the child's original permalink is returned.
For this action to be called, you must enable the Broadcast "use parent permalink" setting.
@since 2017-06-01 12:57:38
**/
function my_threewp_broadcast_override_child_permalink( $action )
{
// These are the post types whose permalinks we want replaced with the parent permalink.
$post_types_to_override = [
'page',
'documentation',
];
if ( in_array( $action->post->post_type, $post_types_to_override ) )
$action->returned_permalink = $action->parent_permalink;
else
$action->returned_permalink = $action->child_permalink;
}
add_action( 'threewp_broadcast_override_child_permalink', 'my_threewp_broadcast_override_child_permalink' );