[Resolved] Wrap embeds in div
-
I’m a little stumped on this one, not sure of the filters to use or the JavaScript to edit.
I want to wrap embeds in a div, so I can have some sort of hook to style the embeds in my theme. I’d prefer this to be done server side but will settle for jQuery.
That said, I’ve been able to wrap iframes with a div by simply writing
$("iframe").wrap("<div class='iframe'/>");
However when an activity item list tab is clicked that code isn’t constant and applied to the new dom elements.Help appreciated.
Thanks
-
Check out the
embed_oembed_html
filter. I think that’s what you need here.I really need to get the hang of these actions and filters.
I tried this
add_filter('embed_oembed_html', 'sc_activity_embed_wrap'); function sc_activity_embed_wrap($content) { echo 111; }
But it doesn’t output the 111 upon inserting or retrieving any items that I assume are passed via
embed_oembed_html
Think of it like this:
- Filters return stuff
- Actions don’t
Here’s an example using the
embed_oembed_html
filter:add_filter( 'embed_oembed_html', function( $html, $url, $attr, $post_ID ) { // Use $html, $url, $attr and $post_ID here if you like. // Wrap the HTML output. $html = '<div>' . $html . '</div>'; // Return $html. return $html; }, 10, 4 );
I’ve added this to functions.php and there is no result in the activity stream.
I’m assuming $html needs to be the activity content but I have no idea where to go for this.
Perhaps that filter hook is for filtering embeds in WordPress content? BuddyPress must have a filter for this. I’ll need to have a dig around…
Can you try the
bp_activity_embed_html
hook?add_filter( 'bp_activity_embed_html', function( $retval ) { return '<div>' . $retval . '</div>'; } );
bp_use_oembed_in_activity
can be used to allow or disallow oEmbeds in activity items.The
bp_activity_embed()
function just adds a bunch of filters and actions. It’s not really for filtering the oEmbed output.It’s ok, I’ve decided that I’m going to build core support into my theme. Enhancements can come later. Thanks for the help.
Cool, no worries!
- The topic ‘[Resolved] Wrap embeds in div’ is closed to new replies.