Template Overrides
WB Polls supports template overrides so you can customize the appearance of polls without modifying plugin files. Copy template files to your theme directory and customize them while keeping the plugin updatable.
How Template Overrides Work
Section titled “How Template Overrides Work”Plugin templates are located in:
wp-content/plugins/buddypress-polls/template/Which templates you can override, and where the override goes:
| Template file | Override location in your theme |
|---|---|
single-wbpoll.php |
buddypress-polls/single-wbpoll.php |
archive-wbpoll.php |
buddypress-polls/archive-wbpoll.php |
poll-dashboard.php |
template/poll-dashboard.php |
The plugin checks the child theme first, then the parent theme, then its own file. Use a child theme.
The other templates (create-poll-shortcode.php, single-wbsurvey.php, archive-wbsurvey.php) are loaded from the plugin and cannot be overridden by copying. Use the hooks and the wb_poll_locate_template filter instead.
Available Templates
Section titled “Available Templates”| Template File | Purpose |
|---|---|
archive-wbpoll.php |
Poll archive page listing all polls |
single-wbpoll.php |
Single poll page displaying one poll |
poll-dashboard.php |
Member poll dashboard, including the create and edit panel |
create-poll-shortcode.php |
Poll creation form for the [wbpoll_create] shortcode (not overridable) |
single-wbsurvey.php, archive-wbsurvey.php |
Survey page and survey archive (not overridable) |
Override Steps
Section titled “Override Steps”Step 1: Create the Override Directory
Section titled “Step 1: Create the Override Directory”Create the folder in your theme (use template instead of buddypress-polls for poll-dashboard.php):
mkdir -p wp-content/themes/your-theme/buddypress-polls/Step 2: Copy the Template
Section titled “Step 2: Copy the Template”Copy the template you want to customize:
cp wp-content/plugins/buddypress-polls/template/single-wbpoll.php \ wp-content/themes/your-theme/buddypress-polls/single-wbpoll.phpStep 3: Customize
Section titled “Step 3: Customize”Edit the copied template. Your theme version takes priority over the plugin version.
Template Details
Section titled “Template Details”single-wbpoll.php
Section titled “single-wbpoll.php”Displays a single standalone poll on its dedicated page.
Template hooks available:
do_action( 'buddypress_polls_before_main_content' );do_action( 'before_single_buddypress_polls' );// Poll content renders heredo_action( 'after_single_buddypress_polls' );do_action( 'buddypress_polls_after_main_content' );Override example:
<?phpget_header();do_action( 'buddypress_polls_before_main_content' );?>
<div class="my-custom-poll-wrapper"> <?php while ( have_posts() ) : the_post(); do_action( 'before_single_buddypress_polls' ); ?> <article id="poll-<?php the_ID(); ?>" class="poll-single"> <header class="poll-header"> <h1><?php the_title(); ?></h1> </header> <div class="poll-content"> <?php the_content(); ?> </div> </article> <?php do_action( 'after_single_buddypress_polls' ); endwhile; ?></div>
<?phpdo_action( 'buddypress_polls_after_main_content' );get_footer();?>archive-wbpoll.php
Section titled “archive-wbpoll.php”Displays the poll archive page listing all published polls.
Template structure:
do_action( 'buddypress_polls_before_main_content' );
if ( have_posts() ) : while ( have_posts() ) : the_post(); do_action( 'before_single_buddypress_polls' ); // Poll card HTML do_action( 'after_single_buddypress_polls' ); endwhile; the_posts_pagination();endif;
do_action( 'buddypress_polls_after_main_content' );create-poll-shortcode.php
Section titled “create-poll-shortcode.php”The poll creation form rendered by the [wbpoll_create] shortcode. It is loaded from the plugin folder and has no theme override.
CSS Customization
Section titled “CSS Customization”Key CSS Classes
Section titled “Key CSS Classes”Single poll pages and the dashboard use these classes:
.polls-single { } /* Single poll page */.polls-single__title { }.polls-single__description { }.polls-status-badge { } /* Status badge */.polls-type-badge { } /* Poll type badge */.wbpoll-question-choices-item-content { } /* One answer option in the voting form */.polls-widget { } /* Widgets */Inspect the page in your browser to find the class for anything else. Class names can change between releases, so prefer the hooks below for larger changes.
Adding Custom CSS
Section titled “Adding Custom CSS”In your theme stylesheet:
.wbpoll-single-poll { background: #f5f5f5; border-radius: 8px; padding: 20px;}Via the Customizer: Navigate to Appearance > Customize > Additional CSS.
With a custom enqueued stylesheet:
function my_poll_styles() { if ( is_singular( 'wbpoll' ) || is_post_type_archive( 'wbpoll' ) ) { wp_enqueue_style( 'my-poll-styles', get_template_directory_uri() . '/css/polls.css', array( 'buddypress-polls' ), '1.0.0' ); }}add_action( 'wp_enqueue_scripts', 'my_poll_styles', 20 );Adding Custom JavaScript
Section titled “Adding Custom JavaScript”The plugin does not dispatch custom DOM events. Enqueue your script after wb-polls-ui (the shared script every poll page loads) and work with the rendered markup.
function my_poll_scripts() { if ( is_singular( 'wbpoll' ) ) { wp_enqueue_script( 'my-poll-scripts', get_template_directory_uri() . '/js/polls.js', array( 'jquery', 'wb-polls-ui' ), '1.0.0', true ); }}add_action( 'wp_enqueue_scripts', 'my_poll_scripts', 20 );Template Location Filter
Section titled “Template Location Filter”Use the wb_poll_locate_template filter to change where the plugin looks for template files:
add_filter( 'wb_poll_locate_template', function( $template, $file_name ) { $custom = get_template_directory() . '/polls/' . $file_name; if ( file_exists( $custom ) ) { return $custom; } return $template;}, 10, 2 );Using Hooks Instead of Full Overrides
Section titled “Using Hooks Instead of Full Overrides”For minor changes, use action hooks instead of overriding entire template files. This approach is safer during plugin updates:
// Add content before the poll without overriding single-wbpoll.phpadd_action( 'before_single_buddypress_polls', function() { echo '<div class="custom-poll-intro">Cast your vote below!</div>';});Best Practices
Section titled “Best Practices”Use Child Themes
Section titled “Use Child Themes”Always place template overrides in a child theme. This preserves your changes during parent theme updates.
Keep Core Functionality
Section titled “Keep Core Functionality”When overriding templates, maintain the essential action hooks and form structure. Removing hooks can break plugin functionality.
Test After Plugin Updates
Section titled “Test After Plugin Updates”When WB Polls updates, compare your overridden templates with the new plugin versions. Template changes in updates may require updating your overrides.
Prefer Filters Over Full Overrides
Section titled “Prefer Filters Over Full Overrides”For small display changes, use filters like wbpoll_form_html or action hooks like before_single_buddypress_polls instead of copying entire template files.

