Using WordPress ‘print_embed_sharing_button()’ PHP function

The print_embed_sharing_button() WordPress PHP function prints the necessary markup for the embed sharing button.

Usage

To use the print_embed_sharing_button() function, simply call it where you want the sharing button to appear:

print_embed_sharing_button();

Parameters

This function has no parameters.

More information

See WordPress Developer Resources: print_embed_sharing_button

Examples

Display embed sharing button in a post template

In this example, we will add the embed sharing button to a post template.

function mytheme_add_embed_sharing_button() {
  print_embed_sharing_button();
}
add_action('the_content', 'mytheme_add_embed_sharing_button');

Display embed sharing button in a custom location

In this example, we will add the embed sharing button to a custom location in your theme.

function mytheme_custom_location() {
  print_embed_sharing_button();
}
add_action('mytheme_custom_hook', 'mytheme_custom_location');

Display embed sharing button with custom text

In this example, we will customize the text of the embed sharing button.

function mytheme_custom_embed_sharing_button() {
  echo '<div class="custom-embed-sharing">';
  print_embed_sharing_button();
  echo '<span>Share this content</span>';
  echo '</div>';
}
add_action('the_content', 'mytheme_custom_embed_sharing_button');

Conditionally display embed sharing button

In this example, we will display the embed sharing button only on single post pages.

function mytheme_conditional_embed_sharing_button() {
  if (is_single()) {
    print_embed_sharing_button();
  }
}
add_action('the_content', 'mytheme_conditional_embed_sharing_button');

Display embed sharing button with custom styles

In this example, we will add custom styles to the embed sharing button.

function mytheme_styled_embed_sharing_button() {
  echo '<div class="styled-embed-sharing">';
  print_embed_sharing_button();
  echo '</div>';
}
add_action('the_content', 'mytheme_styled_embed_sharing_button');

function mytheme_embed_sharing_styles() {
  echo '<style>
    .styled-embed-sharing {
      background-color: #f0f0f0;
      padding: 10px;
      border-radius: 5px;
    }
  </style>';
}
add_action('wp_head', 'mytheme_embed_sharing_styles');