You can use add_shortcode()
to register custom Shortcodes for restricting access to certain parts of the post content.
And here\'s a working example, with specific to your case:
function my_rp_shortcode( $atts = [], $content = \'\', $tag = \'\' ) {
if ( \'if-rp\' === $tag ) {
// Return $content if the URL query string has action=rp.
return ( isset( $_GET[\'action\'] ) && \'rp\' === $_GET[\'action\'] ) ? $content : \'\';
} else { // if-not-rp
// Return $content if the URL query string doesn\'t have action=rp.
return ( empty( $_GET[\'action\'] ) || \'rp\' !== $_GET[\'action\'] ) ? $content : \'\';
}
}
add_shortcode( \'if-rp\', \'my_rp_shortcode\' );
add_shortcode( \'if-not-rp\', \'my_rp_shortcode\' );
You\'d add the code to the theme functions file and use the Shortcodes like so:
[if-rp]
This content is shown only if the query string "action" is set to "rp".
Example: example.com/login/?action=rp
[/if-rp]
[if-not-rp]
This content is shown only if the query string "action" is NOT set or the value is NOT "rp".
Example: example.com/login/?action= (empty "action")
Example 2: example.com/login/ (no "action")
[/if-not-rp]
You can change the logic, use two independent Shortcode functions, replace the tags (if-rp
and if-not-rp
), etc. if you want to. :)