get_privacy_policy_url()
Returns the URL of the privacy policy page.
The privacy page can be specified in the admin panel Settings > Privacy.
The ID of the privacy policy page is stored in the option get_option( 'wp_page_for_privacy_policy' ).
Uses: get_option(), get_permalink()
Used By: get_the_privacy_policy_link()
Hooks from the function
Returns
String. The URL of the privacy policy page or an empty string if the page does not exist.
Usage
get_privacy_policy_url();
Examples
#1 Display a link to the privacy policy page
If such a page is not on the site the link will be #.
<?php $url = get_privacy_policy_url() ?: '#'; ?> By clicking the "Register" button, you agree to the <a href="<?= esc_url( $url ) ?>" target="_blank">privacy policy</a>.
Changelog
| Since 4.9.6 | Introduced. |
get_privacy_policy_url() get privacy policy url code WP 7.0
function get_privacy_policy_url() {
$url = '';
$policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
if ( ! empty( $policy_page_id ) && get_post_status( $policy_page_id ) === 'publish' ) {
$url = (string) get_permalink( $policy_page_id );
}
/**
* Filters the URL of the privacy policy page.
*
* @since 4.9.6
*
* @param string $url The URL to the privacy policy page. Empty string
* if it doesn't exist.
* @param int $policy_page_id The ID of privacy policy page.
*/
return apply_filters( 'privacy_policy_url', $url, $policy_page_id );
}