Skip to:
Content
Pages
Categories
Search
Top
Bottom

Enable shortcode in BuddyPress activity feed


  • Fábio Roque
    Participant

    @fabioroque92

    Hi everyone, I already try some solutions like

    add_filter( ‘bp_nouveau_activity_content’, ‘do_shortcode’,);

    or

    function test() {
    add_filter( ‘bp_nouveau_activity_content’, ‘do_shortcode’, 1 );
    }
    add_action(‘bp_init’, ‘test’);

    But I can’t solve this problem, somebody knows how to enable the shortcodes in activity feed? thnks

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

  • shanebp
    Moderator

    @shanebp

    That is not how shortcodes work.
    You need to put it in the template:
    buddypress\bp-templates\bp-nouveau\buddypress\activity\entry.php
    Overload that template in your child theme and then make your change.
    Since you are in the template, just make a call to a custom function – no need for a shortcode.


    Fábio Roque
    Participant

    @fabioroque92

    I don’t have another option to enable the shortcodes in activity posts ?

    I found this:

    Enable Shortcodes in Activity Screen of Buddypress

    but doesn’t work


    shanebp
    Moderator

    @shanebp

    That solution was for the old templates – 6 years ago!

    You could use this hook: do_action( 'bp_activity_entry_content' );
    Found in: buddypress\bp-templates\bp-nouveau\includes\activity\template-tags.php
    Again – no need to use a shortcode.


    Fábio Roque
    Participant

    @fabioroque92

    I think I wasn’t clear in what I’m looking for.

    I want to include a contactform7 shortcode in a activity feed


    shanebp
    Moderator

    @shanebp

    Then use the do_action hook to call a function that has a do_shortcode in it.
    Or put the shortcode call in the template.


    Fábio Roque
    Participant

    @fabioroque92

    Sorry mate but I can’t solved this problem.

    `
    function enable_shortcodes_in_feed()
    {

    add_filter( ‘ ??? ‘, ‘do_shortcode’, 1);

    }
    add_action( ‘bp_activity_entry_content’, enable_shortcodes_in_feed’ ); `

    And I tried add the do_shortcode in the template but doesn’t works too


    shanebp
    Moderator

    @shanebp

    That is not how shortcodes work.
    I suggest you read the WP docs re shortcodes.

    And maybe try the generator so you have an example.


    Fábio Roque
    Participant

    @fabioroque92

    I already have the shortcode created, but when I put the shortcode in activity feed he doesn’t work.

    I want to do this: https://buddypress.org/support/topic/enable-shortcodes-in-activity-screen-of-buddypress/ but in the new version of buddypress.


    shanebp
    Moderator

    @shanebp

    If you have the shortcode set up properly, you should be able to run it anywhere on the site.
    To confirm, try running it on a non-BP page.
    If it works there, it should work in the activity > entry template


    Fábio Roque
    Participant

    @fabioroque92

    if I go to the entry template and put <?php echo do_shortcode([shortcode)] ?> it Works, but if I insert a shortcode directly in the feed doesn’t work


    Fábio Roque
    Participant

    @fabioroque92

    Hi, I already found a solution.

    /**
     * Enable shortcode rendering in BuddyPress activity.
     */
    add_filter( 'bp_get_activity_content_body', function ( $content ) {
    
    	echo do_shortcode( $content );
    
    }, 0 );

    futureyoon
    Participant

    @futureyoon

    Hi Fabio,

    I happened to come across your post and was trying to use it on buddyboss theme and plugin but not sure why nothing is happening.

    I enabled your code in code snippet and i post a shortcode in activity feed, but nothing shows up…

    Do you have any idea?

    Thank you


    Fábio Roque
    Participant

    @fabioroque92

    Hi @futureyoon

    Try this

    /**
     * Render shortcodes on feed posts
     */
    function enable_shortcode_bp_activity($content) {
        $content = stripslashes($content);
    	return do_shortcode($content);
    }
    
    add_filter('bp_get_activity_content_body', 'enable_shortcode_bp_activity', 0);

    ps: this was not tested in buddyboss 2.0


    futureyoon
    Participant

    @futureyoon

    Thank you so much, Fabio.

    Yes the code seems working.
    I can see that it’s reacting as in I can see some shortcodes are showing up but not particularly for H5P shortcode.

    https://snipboard.io/kebxSK.jpg

    I understand this might be beyond your knowledge, but do you happen to know how to enable the H5P shortcode in activity feed?

    Appreciate that.


    Fábio Roque
    Participant

    @fabioroque92

    when I developed this, I had problems with css styles, js files… maybe is something like that, I don’t know, I never used the H5P.

    I used this code to insert my own shortcodes!

    I would like to help you, but without testing is difficult. Try search in H5P documentation!


    futureyoon
    Participant

    @futureyoon

    I think I found the reason but not sure how to solve.
    I added the shortcode in a page to see how H5P is working and found out that H5P is using ‘iframe’ method.

    https://snipboard.io/NCvBSL.jpg

    but I beleive that buddyboss is not allowing the iframe on the activity feed (not sure, I might be wrong).

    then do you have any idea how to enable the iframe feature on the activity feed?
    so that possibly h5p shortcode is working.

    Please let me know your thought.

    Thank you so much

Viewing 16 replies - 1 through 16 (of 16 total)
  • You must be logged in to reply to this topic.
Skip to toolbar