• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Programming / WordPress Code to Get the Privacy Policy URL

WordPress Code to Get the Privacy Policy URL

Last updated on October 9, 2018 by Sal Ferrarello

With WordPress version 4.9.6 a number of Privacy Related Options, Hooks and Capabilities were added (predominantly in response to the EU General Data Protection Regulation (GDPR) legislation.

Specifically, a new option wp_page_for_privacy_policy has been introduced, which stores the page id of the site’s privacy policy page.

Setting the Option

If you are running, WordPress 4.9.6 or newer, you can go to Settings > Privacy (wp-admin/privacy.php) where you will see something like the following

Here you can select (or create) the Privacy Policy page for your website. This will populate the wp_page_for_privacy_policy option.

Using the Option

To use this value to display the Privacy Policy URL, you can use something like

echo esc_url( get_permalink( get_option( 'wp_page_for_privacy_policy' ) ) );

a more complex example might look like

printf(
    '<a href="%s">%s</a>',
    get_permalink( get_option( 'wp_page_for_privacy_policy' ) ),
    esc_html( __( 'Privacy Policy' ) )
);

Resources

WordPress Privacy Related Options, Hooks and Capabilities

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Programming Tagged With: privacy, WordPress

Reader Interactions

Comments

  1. Jeffrey says

    September 11, 2018 at 6:58 am

    You’re missing a closing parenthesis

    echo esc_url( get_permalink( get_option( 'wp_page_for_privacy_policy' ) ) );
    Reply
    • Sal Ferrarello says

      September 11, 2018 at 9:08 am

      Hi Jeffrey,

      Good catch about the missing closing parenthesis. I’ve updated the code in this post. Thanks for your help.

      Reply
  2. Oleg says

    October 8, 2018 at 11:14 am

    The second and third parameters of the printf function should be reversed in order.

    Reply
    • Sal Ferrarello says

      October 9, 2018 at 3:18 pm

      Hi Oleg,

      Good catch – thank you. I’ve updated this post and corrected the order of the parameters for prinf(). Thanks.

      Reply
  3. RickH says

    March 11, 2022 at 2:24 pm

    All well and good (found this with a search) … but what about *setting* the value?

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in