New Privacy Policy page helpers coming in 5.2

In the WordPress 5.2 update new helpers have been added to make designing the Privacy Policy page easier.

In total 4 new items were added which are available to use in themes or plugins. There are 2 new CSS classes to help target the Privacy Policy page and menu items on the frontend, a new function that can be used in conditionals and a brand new template available to allow themes to design or style the Privacy Policy page anyway they choose.

  • is_privacy_policy() conditional query function
  • privacy-policy.php template
  • .privacy-policy body class
  • .menu-item-privacy-policy menu item class

You can start to take advantage of these items immediately upon the release of WordPress 5.2.

Backwards Compatibility

If the new additions are used on older versions of WordPress prior to 5.2 the template will not be used and the new CSS classes will not be output. The only backwards compatibility concern with using these new helpers is with the is_privacy_policy() function.

To support the is_privacy_policy() function pre-5.2 the following shim can be added to the theme or plugin;

<?php
if ( ! function_exists( 'is_privacy_policy' ) ) {
        function is_privacy_policy() {
                return get_option( 'wp_page_for_privacy_policy' ) && is_page( get_option( 'wp_page_for_privacy_policy' ) );
        }
}