Hiding Comments Icon On oembed

I need to hide the comments icon on oEmbed widgets or disable the comments icon feature completely. I’ve been looking at the following links:

https://developer.wordpress.org/reference/files/wp-includes/embed.php/
https://core.trac.wordpress.org/browser/tags/4.5/src/wp-includes/embed.php

What I came up with after thinking for a while was this. I feel its a bit hacky, however it works. I copied the code from the_embed_site_title() and added inline style to display none at the end of it, then hook into with it a filter.

I added .wp-embed-comments{ display: none; } in the last $site_title variable before being returned.

function groovy() {
  $site_title = sprintf(
  '<a href="https://wordpress.stackexchange.com/questions/226991/%s" target="_top"><img src="https://wordpress.stackexchange.com/questions/226991/%s" srcset="https://wordpress.stackexchange.com/%s 2x" width="32" height="32" alt="" class="wp-embed-site-icon"/><span>%s</span></a>',
    esc_url( home_url() ),
    esc_url( get_site_icon_url( 32, admin_url( 'images/w-logo-blue.png' ) ) ),
    esc_url( get_site_icon_url( 64, admin_url( 'images/w-logo-blue.png' ) ) ),
    esc_html( get_bloginfo( 'name' ) )
  );
  $site_title="<div class="wp-embed-site-title">" . $site_title . '</div><style>.wp-embed-comments{ display: none; }</style>';

  return $site_title;
}
add_filter( 'embed_site_title_html', 'groovy', 10, 2 );

Is there a better way?

1 Answer
1

Pretty sure you can just remove them entirely:

remove_action( 'embed_content_meta', 'print_embed_comments_button' );

Leave a Comment