Using WordPress ‘is_privacy_policy()’ PHP function

The is_privacy_policy() WordPress PHP function determines whether the query is for the Privacy Policy page.

Usage

if ( is_privacy_policy() ) {
  // Your custom code here
}

Parameters

  • None

More information

See WordPress Developer Resources: is_privacy_policy()

Examples

Display a message on the Privacy Policy page

Display a custom message on the Privacy Policy page.

if ( is_privacy_policy() ) {
  echo '**Welcome to our Privacy Policy page!**';
}

Add a specific CSS class to the body tag on the Privacy Policy page

Add a unique CSS class to the body tag on the Privacy Policy page.

function custom_body_class( $classes ) {
  if ( is_privacy_policy() ) {
    $classes[] = 'privacy-policy-page';
  }
  return $classes;
}
add_filter( 'body_class', 'custom_body_class' );

Display a custom widget only on the Privacy Policy page.

if ( is_privacy_policy() ) {
  dynamic_sidebar( 'privacy-policy-widget' );
}

Redirect users to the homepage if they are not logged in and try to access the Privacy Policy page

Restrict access to the Privacy Policy page to logged-in users only.

function restrict_privacy_policy() {
  if ( is_privacy_policy() && !is_user_logged_in() ) {
    wp_redirect( home_url() );
    exit;
  }
}
add_action( 'template_redirect', 'restrict_privacy_policy' );

Show a GDPR consent banner on every page except the Privacy Policy page.

if ( !is_privacy_policy() ) {
  get_template_part( 'template-parts/gdpr-consent-banner' );
}