Skip to:
Content
Pages
Categories
Search
Top
Bottom

BBPress Customization with Custom Plugin


  • farooqayubi
    Participant

    @farooqayubi

    I have created a custom plugin, to do customization in BBPRESS templates, & Paid Membership Pro.. Everything other customization is working fine, But the template i want to show instead of bbpress default loop-topics.php template is not showing it /wp-content/plugins/pharmacy-membership-forum/pharmacy-membership-forum.php – Mian Plugin File /wp-content/plugins/pharmacy-membership-forum/includes/templates.php – the file where we are connecting loop-topics.php /wp-content/plugins/pharmacy-membership-forum/templates/bbpress/loop-topics.php – new template for loop-topics.php templates.php Code it appears that bbPress is not prioritizing your custom templates, or something else might be going wrong during the template loading process.

    <?php
    // Prevent direct access
    if ( ! defined( 'ABSPATH' ) ) {
        exit;
    }
    
    // Hook into plugins_loaded to ensure bbPress is loaded
    add_action('plugins_loaded', 'cmp_override_bbpress_templates');
    
    /**
     * Function to override bbPress templates.
     */
    function cmp_override_bbpress_templates() {
        // Add filter to override bbPress template parts
        add_filter('bbp_get_template_part', 'cmp_custom_template_parts', 10, 3);
    }
    
    /**
     * Filter to override bbPress templates.
     *
     * @param array  $templates Array of template paths.
     * @param string $slug      Template slug.
     * @param string $name      Template name.
     * @return array Modified array of template paths.
     */
    function cmp_custom_template_parts($templates, $slug, $name) {
        $plugin_template_path = plugin_dir_path(dirname(__FILE__)) . 'templates/bbpress/';
    
        // Check for various templates and override them
        if ($slug === 'loop' && $name === 'topics') {
            $custom_template_path = $plugin_template_path . 'loop-topics.php';
            array_unshift($templates, $custom_template_path);
            
        }
    
        if ($slug === 'content' && $name === 'single-forum') {
            $custom_template_path = $plugin_template_path . 'content-single-forum.php';
            array_unshift($templates, $custom_template_path);
        }
    
        if ($slug === 'loop' && $name === 'single-topic') {
            $custom_template_path = $plugin_template_path . 'loop-single-topic.php';
            array_unshift($templates, $custom_template_path);
        }
        
        return $templates;
        
    }
Viewing 1 replies (of 1 total)

  • Robin W
    Moderator

    @robin-w

    so are you saying that loop-topics is not working, but loop-single-topic and content-single forum are working?

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