Password Protect Open Graph Meta Tags

This article will walk you through the following sections:

What are Open Graph meta tags?

Open Graph is a protocol first introduced by Facebook in 2010.

Soon, it has become a standard way to control which elements of your page are shared on major social media platforms, such as Facebook and Twitter.

As a result, using Open Graph meta tags could play a vital role in the conversions and click-through rates of your sites. In other words, the tags are the solution to make your content more shareable and clickable on social media.

Should you protect Open Graph meta tags?

Password Protect WordPress (PPWP) plugin helps secure your private content, except for the meta tags, from unwanted users. Here’re why we don’t protect Open Graph meta tags:

  • The meta tags allow you to define and display the key information of your private page, such as page title, featured image, and page excerpt on social media.
    • They help tell your readers what the content is about at a glance. Hiding the page’s open graph makes social sharing less meaningful, doesn’t it?
  • Many users, especially those who own a business, want to show the page excerpt or Open Graph meta description tags to entice the audiences to take specific actions, e.g. joining a membership site or buying certain products.
    • In short, Open Graph protection would do more harm than good.

Missing Open Graph meta tags and SEO information when protecting entire site

If your website is under sitewide protection, when you share your private content on social media, the Open Graph meta tags and other SEO information will not show up. It’s simply because you’re actually sharing the login page which doesn’t contain any predefined information.

Fortunately, it’s possible to let your Open Graph meta tags and other SEO information display on social media even when protecting the entire site.

Simply add the following code to your (child) theme functions.php

add_filter( 'ppw_custom_header_form_entire_site', 'ppwp_handle_open_graph' );

function ppwp_handle_open_graph() {
   add_action('wp_enqueue_scripts', 'ppwp_remove_all_theme_scripts', 100);
   wp_head();
}

/* remove unnecessary external scripts or styles
Your inline scripts or styles will still display on your header
*/
function ppwp_remove_all_theme_scripts() {
   global $wp_styles;
   global $wp_scripts;
   if ( isset( $wp_styles->queue ) ) {
      $wp_styles->queue = array();
   }
   if ( isset( $wp_scripts->queue ) ) {
      $wp_scripts->queue = array();
   }
}

 

Lasted updated on May 27, 2020