Skip to:

Bug associating a newly created template to custom tab

  • freddurst1805


    WP version 4.9.2
    BP version 2.9.2

    Hello everyone,

    I have a very sad issue that I cannot solve. I spent something like 3 hours and nothing helped me.
    I create a new tab on the profile page with “bp_core_new_nav_item” this way :

    function test_custom_tab() {
    global $bp;
    bp_core_new_nav_item( array(
    ‘name’ => __( ‘My recent Posts’, ‘buddypress’ ),
    ‘slug’ => ‘test’,
    ‘position’ => 100,
    ‘screen_function’ => ‘screen_test’,
    ‘show_for_displayed_user’ => true
    ) );
    add_action(‘bp_setup_nav’, ‘test_custom_tab’, 1000);

    So at this step everything is OK. But now I want to associate a view to this tab. I do this way :

    function screen_test () {
    add_action( ‘bp_template_title’, ‘screen_test_title’ );
    add_action( ‘bp_template_content’, ‘screen_test_content’ );
    bp_core_load_template( apply_filters( ‘bp_core_template_plugin’, ‘members/single/test’ ) );
    function screen_test_title() {
    echo ‘My new Page Title’;
    function screen_test_content() {
    echo ‘My new Page Content’;

    After I create the “test.php” file into my plugin directory :

    I registred my “templates” directory as a template directory for BuddyPress this way :

    function bp_tol_register_template_location() {
    return dirname( __FILE__ ) . ‘/templates/’;

    function bp_tol_start() {
    if( function_exists( ‘bp_register_template_stack’ ) )
    bp_register_template_stack( ‘bp_tol_register_template_location’ );
    add_action(‘bp_init’, ‘bp_tol_start’);

    And the issue is that instead of displaying the content of the file “test.php” it’s displaying a list of member from I don’t know where it takes this page …

    Please help me this issue is horrible

Viewing 1 replies (of 1 total)

  • vapvarun


    Hi @freddurst1805
    You can use this approach to load template files from your plugin

    function screen_test(){
            add_action('bp_template_title', 'screen_test_title');
            bp_core_load_template(apply_filters('bp_core_template_plugin', 'members/single/plugins'));
    // buddypress-template folder and file name which you have created inside your plugin.
        function screen_test_content() {
            	include 'buddypress-template/some-template.php';
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar