1. Customize
  2. Restrict Content
  3. Adding a shortcode as message on [gamipress_restrict_content] shortcode

Adding a shortcode as message on [gamipress_restrict_content] shortcode

The following snippet shows how to add a shortcode as message on [gamipress_restrict_content] shortcode.

In addition, this snippet includes examples of conditionals you can apply based on [gamipress_restrict_content] shortcode attributes or conditional you can apply to guests (not logged in visitors).

function my_prefix_custom_restrict_content_shortcode_restricted_output( $output, $atts, $content ) {

    $shortcode = '[your_shortcode attribute="value"]'; // Setup here the shortcode you want

    // $atts contains all [gamipress_restrict_content] attributes you passed,
    // so, for example, you can apply a custom shortcode per content id
    if( $atts['id'] === 'my-content-id' ) {
        $shortcode = '[shortcode_just_for_this_content_id attribute="value"]';
    }

    // Also, there is another check to add another shortcode if user is not logged in
    if( ! is_user_logged_in() ) {
        $shortcode = '[shortcode_for_guests attribute="value"]';
    }

    $output .= $shortcode;

    return $output;

}
add_filter( 'gamipress_restrict_content_shortcode_restricted_output', 'my_prefix_custom_restrict_content_shortcode_restricted_output', 10, 3 );

How can we help?