Using WordPress ‘get_the_privacy_policy_link()’ PHP function

The get_the_privacy_policy_link() WordPress PHP function returns the privacy policy link with formatting, when applicable.

Usage

echo get_the_privacy_policy_link( $before, $after );

Parameters

  • $before (string) Optional: Display before privacy policy link. Default: ”
  • $after (string) Optional: Display after privacy policy link. Default: ”

More information

See WordPress Developer Resources: get_the_privacy_policy_link()

Examples

This example adds the privacy policy link to the footer of your WordPress theme.

function add_privacy_policy_link_to_footer() {
  echo get_the_privacy_policy_link( '<p>', '</p>' );
}
add_action( 'wp_footer', 'add_privacy_policy_link_to_footer' );

This example adds the privacy policy link to the navigation menu.

function add_privacy_policy_link_to_menu( $items, $args ) {
  if ( $args->theme_location == 'primary' ) {
    $items .= '<li>' . get_the_privacy_policy_link() . '</li>';
  }
  return $items;
}
add_filter( 'wp_nav_menu_items', 'add_privacy_policy_link_to_menu', 10, 2 );

This example shows how to add custom text before and after the privacy policy link.

echo get_the_privacy_policy_link( 'Our ', ' is available for review.' );

This example checks if a privacy policy page is set and displays the link only if available.

if ( function_exists( 'get_the_privacy_policy_link' ) ) {
  echo get_the_privacy_policy_link();
}

This example adds the privacy policy link to the comment form.

function add_privacy_policy_link_to_comment_form( $fields ) {
  $privacy_link = get_the_privacy_policy_link();
  if ( $privacy_link ) {
    $fields['comment_notes_after'] .= '<p>' . $privacy_link . '</p>';
  }
  return $fields;
}
add_filter( 'comment_form_defaults', 'add_privacy_policy_link_to_comment_form' );