Skip to content

Instantly share code, notes, and snippets.

@VR51
Last active June 18, 2020 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VR51/84b9ab89681d0677bd60d8b8565a6cb9 to your computer and use it in GitHub Desktop.
Save VR51/84b9ab89681d0677bd60d8b8565a6cb9 to your computer and use it in GitHub Desktop.
WordPress Privacy Page Shortcode
<?php
function privacy_page_sc_vr51( $atts ) {
# Creates a Privacy Page link shortcode.
# Use as [privacy title="Privacy Page Title"] or [privacy]
# Default page title is Privacy Page.
# Page link points to the Privacy Page set in Dashboard > Privacy.
# The privacy page will only display if the page is public (status = publish).
# Place this snippet into the site theme's functions.php file, a custom functions plugin or some other
# suitable place.
$atts = shortcode_atts(
array(
'title' => 'Privacy Policy'
), $atts
);
$title = sanitize_text_field( $atts['title'] );
# See wp-admin/includes/class-wp-privacy-policy-content.php
$privacy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
if ( ! empty($privacy_page_id) && get_post_status( $privacy_page_id ) == 'publish' ) {
$link = get_privacy_policy_url();
return "<a href=\"$link\" />$title</a>";
} else {
return;
}
}
add_shortcode( 'privacy', 'privacy_page_sc_vr51' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment