WordPress Snippets at WPcustoms

Add bootstrap classes for WP tables

Bootstrap requires custom table classes. If a table is added to the_content this function with automatically add those classes. You can also add other classes i.e. table table-responsive.


/**
 * Snippet Name: Add bootstrap classes for WP tables
 * Snippet URL: https://wpcustoms.net/snippets/add-bootstrap-classes-wp-tables/
 */
  function wpc_add_custom_table_class( $content ) {
return str_replace( '<table>', '<table class="table table-hover">', $content );
}
add_filter( 'the_content', 'wpc_add_custom_table_class' );