0

How can I access the $atts in a BuddyPress template?

function test_shortcode_callback( $atts, $content='' ) {

    ob_start();

    shortcode_atts(
        array(
            'foo' => 'this is foo',
            'bar' => 'default bar',
        ), $atts, 'test_shortcode' );

    bp_get_template_part('my-template');

    return ob_get_clean();

}
add_shortcode( 'test_shortcode', 'test_shortcode_callback' );

Unlike load_template, bp_get_template_part does not have an $args parameter. In the template, has_shortcode( $post->post_content, 'test_shortcode' ); returns true .

But how can the $atts be accessed? I could store them in post meta, but I hope there is a simpler approach.

1 Answer 1

0

Use a global and set the value to $atts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.