Using WordPress ‘print_embed_sharing_dialog()’ PHP function

The print_embed_sharing_dialog() WordPress PHP function prints the necessary markup for the embed sharing dialog.

Usage

To use the print_embed_sharing_dialog() function, simply call it where you want the embed sharing dialog to appear:

print_embed_sharing_dialog();

Parameters

This function does not have any parameters.

More information

See WordPress Developer Resources: print_embed_sharing_dialog()

Examples

Displaying the embed sharing dialog in a custom template

In this example, we’ll display the embed sharing dialog in a custom template.

function my_custom_template() {
  // Your template code goes here

  // Call print_embed_sharing_dialog() to display the embed sharing dialog
  print_embed_sharing_dialog();

  // Rest of your template code
}

Adding the embed sharing dialog to a post

In this example, we’ll add the embed sharing dialog to a post using the the_content filter.

function add_embed_sharing_dialog_to_post( $content ) {
  // Append the embed sharing dialog to the post content
  ob_start();
  print_embed_sharing_dialog();
  $embed_dialog = ob_get_clean();

  return $content . $embed_dialog;
}
add_filter( 'the_content', 'add_embed_sharing_dialog_to_post' );

Displaying the embed sharing dialog in a widget

In this example, we’ll display the embed sharing dialog in a custom widget.

class Embed_Sharing_Widget extends WP_Widget {
  public function widget( $args, $instance ) {
    // Output the widget content
    echo $args['before_widget'];

    // Call print_embed_sharing_dialog() to display the embed sharing dialog
    print_embed_sharing_dialog();

    echo $args['after_widget'];
  }
}
add_action( 'widgets_init', function() {
  register_widget( 'Embed_Sharing_Widget' );
});

Adding the embed sharing dialog to a shortcode

In this example, we’ll create a shortcode that displays the embed sharing dialog.

function embed_sharing_dialog_shortcode() {
  ob_start();
  print_embed_sharing_dialog();
  return ob_get_clean();
}
add_shortcode( 'embed_sharing_dialog', 'embed_sharing_dialog_shortcode' );

Displaying the embed sharing dialog using an action hook

In this example, we’ll use an action hook to display the embed sharing dialog at a specific location in the theme.

function my_embed_sharing_dialog_action() {
  print_embed_sharing_dialog();
}
add_action( 'my_theme_hook', 'my_embed_sharing_dialog_action' );