BuddyDev

Search

how to add shortcode to top of activity feed

  • Participant
    Level: Enlightened
    Posts: 26
    Peter Fae on #13931

    Greetings. I am wishing to put a shortcode at the top of the page that the activity feed is on.

    Specifically, I’d like to put a revolution slider shortcode up top. How is this done?

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #13933

    Hello Peter,

    Thank you for posting. Try the following code in your “bp-custom.php” file

    
    
    function buddydev_add_slider() {
    	echo do_shortcode( '[your-short-code]' ); // Replace shortcode with your one
    }
    add_action( 'bp_before_directory_activity', 'buddydev_add_slider' );
    
    

    If you do not know about “bp-custom.php” file refer the following url.
    https://codex.buddypress.org/themes/bp-custom-php/

    Let me know if it works or not.

    Thank You
    Ravi

    • This reply was modified 6 years, 9 months ago by Ravi.
  • Participant
    Level: Enlightened
    Posts: 26
    Peter Fae on #13937

    mmm…. this is the second time that I’ve tried to add something to a bp-custom.php file that I’d created in the plugins directory. yet I get a line of code at the top of my screen that layers over everything else.

    Did I not set u p the bp-custom.php file in the right place? Is my syntax out?

    This is what it says in my bp-custom.php file –>

    <?php
    // hacks and mods will go here
    ?>

    function buddydev_add_slider() {
    echo do_shortcode( ‘[your-short-code]’ ); // Replace shortcode with your one
    }
    add_action( ‘bp_before_directory_activity’, ‘buddydev_add_slider’ );

    … in order to use another BP code, I had to put it into the functions.php file of my child theme. When I tried to put the code into the bp-custom.php file in the /plugins directory, I got the same effect, code on top of the site.

    ????

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #13939

    Hello Peter,

    Please post me your any whole file code into postbin. You can refer the following url.

    https://pastebin.com/

    Thank You
    Ravi

  • Participant
    Level: Enlightened
    Posts: 26
    Peter Fae on #13940

    mmm…. this is the second time that I’ve tried to add something to a bp-custom.php file that I’d created in the plugins directory. yet I get a line of code at the top of my screen that layers over everything else.

    Did I not set u p the bp-custom.php file in the right place? Is my syntax out?

    This is what it says in my bp-custom.php file –>

    ‘<?php
    // hacks and mods will go here
    ?>

    function buddydev_add_slider() {
    echo do_shortcode( ‘[your-short-code]’ ); // Replace shortcode with your one
    }
    add_action( ‘bp_before_directory_activity’, ‘buddydev_add_slider’ );’

    … in order to use another BP code, I had to put it into the functions.php file of my child theme. When I tried to put the code into the bp-custom.php file in the /plugins directory, I got the same effect, code on top of the site.

    ????

    (is that better? with the post code?)

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #13941

    Hi Peter,
    Your problem is

    
    // hacks and mods will go here
    ?>
    
    

    You should not add code after closing the php tag.

    Remove this line

    
    ?>
    

    and give it a try.

    Best Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 26
    Peter Fae on #14040

    that worked! Thank you so much.

    I have two questions regarding this.

    ONE – this created the revolution slider in the container that the activity feed is in, which is beautiful. However, I’d like to see the revolution slider *below the masthead* of the theme, which is ABOVE the container/sidebar area.

    When I asked this question to the developers at X-Theme, they provided this info –>

    Hey @Peter_Fae,

    Please disregard the previous advice. To output custom content in above the masthead, you can hook to x_after_site_begin action. The next thing is to detect if the page is an activity page and display your slider in the area using the do_shortcode function and your slider’s shortcode. Regretfully, the bp_is_activity conditional of BuddyPress does not seam to work so you will need to hire a third party developer who is an expert in BuddyPress or contact BuddyPress support to know what is the correct conditional. The code should look like this.

    ‘add_action(‘x_after_site_begin’, ‘slider_above_activity’);

    function slider_above_activity() {
    if ( bp_is_activity() ) {
    echo do_shortcode(‘[rev_slider alias=”gym-classes”]’);
    }
    }’

    what is the conditional to use here?

    TWO –

    In the concept I’m planning, I’d like to have a *specific* revolution slider for particular Profiles in Buddypress, while having a large revolution slider above the feed/sidebar on the main activity feed.

    As the above question tackles how do I showcase the revolution slider on the activity page below the masthead yet above hte container/sidebar, I would also like to know, how do I place a revolution slider like we did in the earlier bit of code which puts it above the activity feed *within* the container, yet with SPECIFIC USER PRIOFILES?

    So, what I’m looking for is a way to set the rev slider for a Profile the way the code You sent me worked, as well as ONE, above

    thank you so much!

    • This reply was modified 6 years, 9 months ago by Peter Fae.
  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #14042

    You can use

    The folloing to show on activity directory

    
    function slider_above_activity_directory() {
    	if ( bp_is_activity_directory() ) {
    		echo do_shortcode( '[rev_slider alias="gym-classes"]' );
    	}
    }
    
    add_action( 'x_after_site_begin', 'slider_above_activity_directory' );
    
    

    or the below code to show on user profile activity

    
    
    function slider_above_user_activity() {
    	if ( bp_is_user_activity() ) {
    		echo do_shortcode( '[rev_slider alias="gym-classes"]' );
    	}
    }
    
    add_action( 'x_after_site_begin', 'slider_above_user_activity' );
    
    

    Hope that helps.

  • Participant
    Level: Enlightened
    Posts: 26
    Peter Fae on #14043

    You are so awesome!!! I am so very, very thankful. Honestly I did not realize how much customization I could do with buddypress. Mmm … can you help with my other thread about the activity feed and profile with oldest-first newest-last?

  • Participant
    Level: Enlightened
    Posts: 26
    Peter Fae on #14046

    Wait, how do I set a *specific* slider to a *specific* user activity?

You must be logged in to reply to this topic.

This topic is: not resolved