Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Wrap embeds in div


  • buddycore
    Participant

    @buddycore

    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

Viewing 12 replies - 1 through 12 (of 12 total)

  • Henry Wright
    Moderator

    @henrywright

    Check out the embed_oembed_html filter. I think that’s what you need here.


    buddycore
    Participant

    @buddycore

    I really need to get the hang of these actions and filters.


    buddycore
    Participant

    @buddycore

    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


    Henry Wright
    Moderator

    @henrywright

    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 );

    buddycore
    Participant

    @buddycore

    I’ve added this to functions.php and there is no result in the activity stream.


    buddycore
    Participant

    @buddycore

    I’m assuming $html needs to be the activity content but I have no idea where to go for this.


    Henry Wright
    Moderator

    @henrywright

    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…


    Henry Wright
    Moderator

    @henrywright

    Can you try the bp_activity_embed_html hook?

    add_filter( 'bp_activity_embed_html', function( $retval ) { 
        return '<div>' . $retval . '</div>';
    } );

    buddycore
    Participant

    @buddycore

    I looked in two places

    I don’t have a clue how to implement these functions, although I am learning.


    Henry Wright
    Moderator

    @henrywright

    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.


    buddycore
    Participant

    @buddycore

    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.


    Henry Wright
    Moderator

    @henrywright

    Cool, no worries!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[Resolved] Wrap embeds in div’ is closed to new replies.
Skip to toolbar