rcp_restricted_content_message

Filters the "this content is restricted" message that gets displayed to unauthorized users.

This function is very similar to rcp_restricted_message, with one subtle difference: rcp_restricted_message gets applied when calling the rcp_format_teaser() function, which is what's responsible for maybe prepending the post/page excerpt to the restriction message. The rcp_restricted_content_message filter gets applied when calling the rcp_get_restricted_content_message() function, where the sole purpose is just to retrieve the "this content is restricted" message.

The global $post variable is available in this context, which would allow you to dynamically change the message based on post ID, post type, etc.

Parameters:

  • $message (string) - The message to be displayed.

Example:

Change the restricted content message for a specific post type.

function ag_rcp_restricted_content_message( $message ) {
	global $post;

	if ( ! $post instanceof WP_Post ) {
		return $message;
	}

	// Change the restriction message for "my_post_type" post type.
	if ( 'my_post_type' === $post->post_type ) {
		$message = __( 'My custom message for my custom post type.' );
	}

	return $message;
}
add_filter( 'rcp_restricted_content_message', 'ag_rcp_restricted_content_message' );
Have more questions? Submit a request
Powered by Zendesk