The get_privacy_policy_template() WordPress PHP function retrieves the path of the Privacy Policy page template in the current or parent template.
Usage
To use the function, simply call it like this:
$template_path = get_privacy_policy_template();
Parameters
This function has no parameters.
More information
See WordPress Developer Resources: get_privacy_policy_template
Examples
Load Privacy Policy Template
Load the Privacy Policy template and include it in your theme:
// Get the template path $template_path = get_privacy_policy_template(); // Include the template if (file_exists($template_path)) { include($template_path); }
Display Privacy Policy Template Content
Display the content of the Privacy Policy template within a div element:
// Get the template path $template_path = get_privacy_policy_template(); // Output the template content if (file_exists($template_path)) { echo '<div class="privacy-policy">'; include($template_path); echo '</div>'; }
Check if Privacy Policy Template Exists
Check if a Privacy Policy template exists in your theme:
// Get the template path $template_path = get_privacy_policy_template(); // Check if the template exists if (file_exists($template_path)) { echo 'Privacy Policy template exists'; } else { echo 'Privacy Policy template does not exist'; }
Modify Privacy Policy Template Path
Use a filter to modify the path of the Privacy Policy template:
function my_custom_privacy_policy_template_path($template) { // Modify the template path return get_template_directory() . '/my-custom-privacy-policy.php'; } add_filter('privacypolicy_template', 'my_custom_privacy_policy_template_path');
Override Privacy Policy Template with a Child Theme
Create a child theme and override the Privacy Policy template in the parent theme:
// In your child theme's functions.php function my_child_theme_privacy_policy_template($template) { // Set the child theme's Privacy Policy template path $child_template = get_stylesheet_directory() . '/child-privacy-policy.php'; // Check if the child theme template exists if (file_exists($child_template)) { return $child_template; } return $template; } add_filter('privacypolicy_template', 'my_child_theme_privacy_policy_template');