Skip to:
Content
Pages
Categories
Search
Top
Bottom

correct way to override bbpress templates

  • @siparker

    Participant

    Hi,

    I want to override a template part in a plugin

    there is a filter on bbp_get_template_part but also in the comments of template-functions.php it mentions you can also add a new location to the template stack.

    Which is the best / most future proof method of these to, for example, override the loop-forums.php template part within a plugin.

    Thanks in advance for the replies.

Viewing 5 replies - 1 through 5 (of 5 total)
  • @robin-w

    Moderator

    If I understand you correctly you want to amend a file in

    wp-content/plugins/bbpress/templates/default/bbpress/

    The easiest way is to copy the relevant file to your child theme

    create a directory on your theme called ‘bbpress’
    ie wp-content/themes/%your-theme-name%/bbpress and copy the file there eg

    wp-content/themes/%your-theme-name%/bbpress/loop-forums.php

    bbPress will now use this template instead of the original
    and you can amend this

    You can also add a location – for instance within a plugin I use I add a location using :

    add_action( 'bbp_register_theme_packages', 'bsp_register_plugin_template1' );
    
    //get the template path
    function bsp_get_template1_path() {
    	return BSP_PLUGIN_DIR . '/templates/templates1';
    }
    
    function bsp_register_plugin_template1() {
    	bbp_register_template_stack( 'bsp_get_template1_path', 12 );
    }
    

    @siparker

    Participant

    Hi

    It is specifically not to add a item into a theme folder as i want the plugin to be totally standalone. with no “Extra” edits required.

    So adding the location can that work to add a location within the plugin to view templates etc.

    so the template lcoation would be /wp-content/plugins/myplugin/templates/replacementbbpresstemplate.php

    Will that work?

    @robin-w

    Moderator

    yes, the code I posted above if placed in your plugin would tell bbpress to look in

    content/plugins/myplugin/templates/templates1/

    @siparker

    Participant

    perfect thanks robin

    @netweb

    Keymaster

    FYI https://wordpress.org/plugins/eighties-bbpress/ is a fantastic example of overriding bbPress templates using a plugin 🙂

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