How to customise a Privacy Policy Guide

WordPress 4.9.6 major update was released to the public on 17 May, 2018 and introduced the new personal data features. This is the first tutorial in the series related to personal data in WordPress.

/10 comments

Let me clarify – WordPress 4.9.6 didn’t receive any functionality to change the content of your existing Privacy Policy pages on the fly. And I do not recommend to do it automatically. Well, if you want it so much, the_content() action hook will help you. Maybe 😁

So, what is the new functionality about? First of all a new Privacy submenu item appeared in the Settings menu. You can create or select any existing privacy page and after that its ID will be available in options, get_option( 'wp_page_for_privacy_policy' ).

New Privacy settings page in WordPress 4.9.6

Do you see “Check out our guide” link? This tutorial is all about it. The guide contains the recommended content for your Privacy Policy page, you can copy it the whole, or just some parts and insert to your Privacy Policy page manually. Plugin authors can add their plugin-related sections to the guide with wp_add_privacy_policy_content() function.

Change the default content in the Privacy Policy Guide

WordPress has a lot of default content in this admin section. But sometimes you may want to customize it to meet your custom theme needs.

Here is how to do it.

add_filter( 'wp_get_default_privacy_policy_content', 'misha_custom_privacy_content' );
function misha_custom_privacy_content( $privacy_content ){
	return wpautop('<h2>Who I am</h2>
 
	I\'m Misha.
 
	<h2>How I collect you data</h2>
 
	I don\'t.');
}

Here is what we got after inserting the above code in… let’s say functions.php of your theme.

We can change the WordPress Privacy Policy Guide default content with the filter hook.

And yes, no way to change the Introduction.

Add a section to Privacy Policy Guide

As I already mentioned before, wp_add_privacy_policy_content() function can help you with it. Note, that you have to run it within admin_init action hook and do not forget to make it compatible with WordPress 4.9.5 and lower.

add_action( 'admin_init', 'misha_custom_plugin_privacy_content' );
function misha_custom_plugin_privacy_content() {
 
	// compatibility with old WordPress versions to avoid error 500
	if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
		return;
	}
 
	wp_add_privacy_policy_content(
		'Plugin by Misha', // section name
		'When you contact us via a contact form, your email will be stored in database for a one week. So we never miss your email!' // content
	);
}

So, once you added it, you could notice, that a notification bubble has been appeared near the Settings Menu.

The privacy notification bubble will appear after any changes in your Privacy Policy Guide.

Go to Settings > Privacy and click "Check out our guide" link.

I wrap the text into wpautop() WP function just to auto-<p> it. And here is what we got.

A custom section in WordPress Privacy Policy Guide

Here is a short video about this functionality as well:

[youtube_embed]https://www.youtube.com/embed/KHgZerh7nKY[/youtube_embed]

If you have any questions, welcome to comments πŸ‘‡

Related

Misha Rudrastyh

Misha Rudrastyh

I love WordPress, WooCommerce and Gutenberg so much. 10 yrs of experience.

Need some custom developer help? Let me know

Follow Misha

Need some help with WordPress?

If you need some professional developer help, I will be happy to assist you.

Contact me Who I am?

Comments — 10

Leave a comment

php js HTML CSS Code