get_the_privacy_policy_link()WP 4.9.6

Returns a link (html) to the privacy policy page.

The privacy policy page can be specified in the admin panel Settings > Privacy. The anchor of the link is the title of the page.

Use the_privacy_policy_link() when you need to immediately display the link on the screen.

Hooks from the function

Returns

String. html code of the link, if the privacy policy page is specified in the admin panel and published. Otherwise, it outputs nothing.

Usage

get_the_privacy_policy_link( $before, $after );
$before(string)
Text/HTML code to place before the link.
Default: ''
$after(string)
Text/HTML code to place after the link.
Default: ''

Examples

0

#1 This will display a link to the privacy policy page.

1-way

$policy_link = get_the_privacy_policy_link();

The result, if the page exists:

<a class="privacy-policy-link" href="https://example.com/privacy-policy/">Privacy Policy</a>

2-way

$policy_link = 'Read the ' . get_the_privacy_policy_link() . ' page before commenting. It's important!";

The result, if the page exists:

Read the <a class="privacy-policy-link" href="https://example.com/privacy-policy/">Privacy Policy</a> page before commenting. It's important!

If the page is not listed or published:

Read the page before commenting. It's important!

3-way

$policy_link = get_the_privacy_policy_link( 'Read the page before commenting ', '. This is important!' );

The result, if the page exists:

Read the page before commenting <a class="privacy-policy-link" href="https://example.com/privacy-policy/">Privacy Policy</a>. It's important!

If the page is not set or not published, it will return an empty string.

Changelog

Since 4.9.6 Introduced.
Since 6.2.0 Added 'privacy-policy' rel attribute.

get_the_privacy_policy_link() code WP 6.9

function get_the_privacy_policy_link( $before = '', $after = '' ) {
	$link               = '';
	$privacy_policy_url = get_privacy_policy_url();
	$policy_page_id     = (int) get_option( 'wp_page_for_privacy_policy' );
	$page_title         = ( $policy_page_id ) ? get_the_title( $policy_page_id ) : '';

	if ( $privacy_policy_url && $page_title ) {
		$link = sprintf(
			'<a class="privacy-policy-link" href="%s" rel="privacy-policy">%s</a>',
			esc_url( $privacy_policy_url ),
			esc_html( $page_title )
		);
	}

	/**
	 * Filters the privacy policy link.
	 *
	 * @since 4.9.6
	 *
	 * @param string $link               The privacy policy link. Empty string if it
	 *                                   doesn't exist.
	 * @param string $privacy_policy_url The URL of the privacy policy. Empty string
	 *                                   if it doesn't exist.
	 */
	$link = apply_filters( 'the_privacy_policy_link', $link, $privacy_policy_url );

	if ( $link ) {
		return $before . $link . $after;
	}

	return '';
}