get_privacy_policy_url(): string

Retrieves the URL to the privacy policy page.

Return

string The URL to the privacy policy page. Empty string if it doesn’t exist.

Source

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 );
}

Hooks

apply_filters( ‘privacy_policy_url’, string $url, int $policy_page_id )

Filters the URL of the privacy policy page.

Changelog

VersionDescription
4.9.6Introduced.

User Contributed Notes

  1. Skip to note 4 content
    /* Basic example */
    /* Get the privacy policy page link*/
    // We store the privacy policy link in a variable
    $privacy_policy_page_link = get_the_privacy_policy_link();
    
    // Our variable will contain something like this
    // <a class="privacy-policy-link" href="http://www.wpdev.local/politica-privacidad/">Política de privacidad</a>
    // Now we can work with this link
  2. Skip to note 6 content
    // Save privacy page info into separate variables
    $policy_page_title  = '';
    $policy_page_url    = '';
    $policy_page_id     = (int) get_option( 'wp_page_for_privacy_policy' );
    
    if ( $policy_page_id && get_post_status( $policy_page_id ) === 'publish' ) {
        $policy_page_title  = get_the_title( $policy_page_id );
        $policy_page_url    = get_permalink( $policy_page_id );
    }
    // Example Uses:
    <?php if($policy_page_id): ?>
    <a href="<?php echo esc_url(get_permalink($policy_page_id)) ?>" target="_blank"><?php echo esc_html(get_the_title($policy_page_id)); ?></a>
    <?php endif; ?>

You must log in before being able to contribute a note or feedback.