Last active
June 18, 2020 19:00
-
-
Save VR51/84b9ab89681d0677bd60d8b8565a6cb9 to your computer and use it in GitHub Desktop.
WordPress Privacy Page Shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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