Skip to:
Content
Pages
Categories
Search
Top
Bottom

Buddypress building shortcode

  • @enriksen

    Participant

    Hi.

    I am trying to make shortcode for youtube.

    So I wrote function in buddypress theme:

    function youtube( $atts, $content = null ) {
    return ”;
    }

    add_shortcode(“youtube”, “youtube”);

    But it wont show youtube video on activity or profile page.
    On activity its blank, on profile: [youtube]8MEOTvkuic4[/youtube].

    What I should do to make youtube appearing everywhere, where this shortcode is added.

    And also I would like to know how to add buttons under “whats new – text field

Viewing 9 replies - 1 through 9 (of 9 total)
  • @chrisclayton

    Participant

    @enriksen
    To ‘do’ shortcodes in different content areas, you will need to filter do_shortcode() into certain functions. See the WordPress codex for documentation on do_shortcode() https://codex.wordpress.org/Function_Reference/do_shortcode and add_filter: https://codex.wordpress.org/Function_Reference/add_filter

    To add it to the activity stream, you’ll want to add
    `add_filter(‘bp_get_activity_content_body’, ‘do_shortcode’); // Adds shortcodes to activity content.`

    Xprofile is similar:
    `add_filter(‘bp_get_the_profile_field_value’, ‘do_shortcode’); // Adds shortcodes to xprofile content.`

    You can find a list of filters in BuddyPress in bp-{component}/bp-{component}-filters in the buddypress files.
    eg: https://buddypress.trac.wordpress.org/browser/trunk/bp-xprofile/bp-xprofile-filters.php

    Remember that this will allow all shortcodes to be used [which is why it’s not on by default], currently there is no way to pick and choose what shortcodes to allow short of using a plugin such as https://wordpress.org/extend/plugins/bbpress2-shortcode-whitelist/.

    @bhguy

    Participant

    ChrisClayton, thanks.

    Can you tell how to enable shortcodes on activity stream of profiles, groups etc.

    Or, is there simple way to enable it everywhere?

    @bhguy

    Participant

    Please someone help, I am stucked with this.
    I want to add buddypress to my site, but cant make this work.
    Tried many ways.

    @chrisclayton

    Participant

    the filter I mentioned above

    `
    add_filter(‘bp_get_activity_content_body’, ‘do_shortcode’); // Adds shortcodes to activity content.
    `

    will add it to the content of all activity (including on the profile page and groups)

    If you need to add it to activity actions as well, you can also use

    `
    add_filter(‘bp_get_activity_action’, ‘do_shortcode’); // Adds shortcodes to activity action.
    `

    @bhguy

    Participant

    On: domain.com/members/admin/activity/13/ = video works.
    On: domain.com/activity = video is not shown, shortcode is not shown, there is nothing, shortcode is not showed as text or anything, shortcode doesnt exist.

    I see only this: admin posted an update 1 day, 8 hours ago.

    @bhguy

    Participant

    `
    function youtube( $atts, $content = null ) {
    return ”;
    }

    add_shortcode(“youtube”, “youtube”);

    add_filter(‘bp_get_the_profile_field_value’, ‘do_shortcode’);

    add_filter(‘bp_get_activity_content_body’, ‘do_shortcode’);
    add_filter(‘bp_get_activity_action’, ‘do_shortcode’);
    `

    I use this, but nothing works on activity, shortcodes disappearing from there, just in full view of article it works.

    @bhguy

    Participant

    My youtube function disappearing here as well as my shortcode from budypress on my site. lol

    function youtube( $atts, $content = null ) {
    return ‘div id=”youtube”iframe width=”200″ height=”200″ src=”http://youtube.com/embed/’.$content.'” frameborder=”0″ allowfullscreen /iframe/div’;
    }

    add_shortcode(“youtube”, “youtube”);

    add_filter(‘bp_get_the_profile_field_value’, ‘do_shortcode’);

    add_filter(‘bp_get_activity_content_body’, ‘do_shortcode’);
    add_filter(‘bp_get_activity_action’, ‘do_shortcode’);

    @chrisclayton

    Participant

    I assume the errors in your div html are because of the forum software and they are fixed in your code?

    The only things I can think of are…

    1. it doesn’t like the iframe
    2. another filter is messing with it

    I’ll have a closer look at it in an hour or two and play around with it and get back to you.

    On a sidenote: BuddyPress provides something out of the box for what you require… if you paste in the url to the youtube video in the activity content – it should automatically embed it. Are you certain you require the shortcode?

    @bhguy

    Participant

    On my hosting oembed is not working.
    That is why I need shortcode.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Buddypress building shortcode’ is closed to new replies.
Skip to toolbar