custom CSS is not applied anymore
-
I have read your faqs for changing the CSS but nothing applies. As a matter of fact, it looks like the custom CSS is not loaded at all (though the box “load the css” is checked), because when I inspect the table in the browser there are no inline codes visible. I believe the default <tr class=”row-1″> gets in the way somehow.
-
If you have access to edit the plugin, go to tablepress > controllers > controller-frontend.php find
public function enqueue_css(): void {
/*
* Bail early if the function is called from some action hook outside of the normal rendering process.
* These are often used by e.g. SEO plugins that render the content in additional contexts, e.g. to get an excerpt via an output buffer.
* In these cases, we don't want to enqueue the CSS, as it would likely not be printed on the page.
*/
if ( doing_action( 'wp_head' ) || doing_action( 'wp_footer' ) ) {
return;
}
// Prevent repeated execution via a static variable.
static $css_enqueued = false;
if ( $css_enqueued && ! doing_action( 'enqueue_block_assets' ) ) {
return;
}
$css_enqueued = true;
/**
* Filters whether the TablePress Default CSS code shall be loaded.
*
* @since 1.0.0
*
* @param bool $use Whether the Default CSS shall be loaded. Default true.
*/
$use_default_css = apply_filters( 'tablepress_use_default_css', true );
$use_custom_css = TablePress::$model_options->get( 'use_custom_css' );
if ( ! $use_default_css && ! $use_custom_css ) {
// Register a placeholder dependency, so that the handle is known for other styles.
wp_register_style( 'tablepress-default', false ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
return;
}
$custom_css = TablePress::$model_options->get( 'custom_css' );
$use_custom_css = $use_custom_css && '' !== $custom_css;
$use_custom_css_file = $use_custom_css && TablePress::$model_options->get( 'use_custom_css_file' );
/**
* Filters the "Custom CSS" version number that is appended to the enqueued CSS files
*
* @since 1.0.0
*
* @param int $version The "Custom CSS" version.
*/
$custom_css_version = (string) apply_filters( 'tablepress_custom_css_version', TablePress::$model_options->get( 'custom_css_version' ) );
$tablepress_css = TablePress::load_class( 'TablePress_CSS', 'class-css.php', 'classes' );
// Determine Default CSS URL.
$rtl = ( is_rtl() ) ? '-rtl' : '';
$unfiltered_default_css_url = plugins_url( "css/build/default{$rtl}.css", TABLEPRESS__FILE__ );
/**
* Filters the URL from which the TablePress Default CSS file is loaded.
*
* @since 1.0.0
*
* @param string $unfiltered_default_css_url URL of the TablePress Default CSS file.
*/
$default_css_url = apply_filters( 'tablepress_default_css_url', $unfiltered_default_css_url );
$use_custom_css_combined_file = ( $use_default_css && $use_custom_css_file && ! SCRIPT_DEBUG && ! is_rtl() && $unfiltered_default_css_url === $default_css_url && $tablepress_css->load_custom_css_from_file( 'combined' ) );
if ( $use_custom_css_combined_file ) {
$custom_css_combined_url = $tablepress_css->get_custom_css_location( 'combined', 'url' );
// Need to use 'tablepress-default' instead of 'tablepress-combined' to not break existing TablePress Extensions.
wp_enqueue_style( 'tablepress-default', $custom_css_combined_url, array(), $custom_css_version );
if ( did_action( 'wp_print_styles' ) ) {
wp_print_styles( 'tablepress-default' );
}
return;
}
if ( $use_default_css ) {
wp_enqueue_style( 'tablepress-default', $default_css_url, array(), TablePress::version );
} else {
// Register a placeholder dependency, so that the handle is known for other styles.
wp_register_style( 'tablepress-default', false ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
}
$use_custom_css_minified_file = ( $use_custom_css_file && ! SCRIPT_DEBUG && $tablepress_css->load_custom_css_from_file( 'minified' ) );
if ( $use_custom_css_minified_file ) {
$custom_css_minified_url = $tablepress_css->get_custom_css_location( 'minified', 'url' );
wp_enqueue_style( 'tablepress-custom', $custom_css_minified_url, array( 'tablepress-default' ), $custom_css_version );
if ( did_action( 'wp_print_styles' ) ) {
wp_print_styles( 'tablepress-custom' );
}
return;
}
$use_custom_css_normal_file = ( $use_custom_css_file && $tablepress_css->load_custom_css_from_file( 'normal' ) );
if ( $use_custom_css_normal_file ) {
$custom_css_normal_url = $tablepress_css->get_custom_css_location( 'normal', 'url' );
wp_enqueue_style( 'tablepress-custom', $custom_css_normal_url, array( 'tablepress-default' ), $custom_css_version );
if ( did_action( 'wp_print_styles' ) ) {
wp_print_styles( 'tablepress-custom' );
}
return;
}
if ( $use_custom_css ) {
// Get "Custom CSS" from options, try minified Custom CSS first.
$custom_css_minified = TablePress::$model_options->get( 'custom_css_minified' );
if ( ! empty( $custom_css_minified ) ) {
$custom_css = $custom_css_minified;
}
/**
* Filters the "Custom CSS" code that is to be loaded as inline CSS.
*
* @since 1.0.0
*
* @param string $custom_css The "Custom CSS" code.
*/
$custom_css = apply_filters( 'tablepress_custom_css', $custom_css );
if ( ! empty( $custom_css ) ) {
wp_add_inline_style( 'tablepress-default', $custom_css );
if ( did_action( 'wp_print_styles' ) ) {
wp_print_styles( 'tablepress-default' );
}
return;
}
}
}replace with
public function enqueue_css(): void {
/** This filter is documented in controllers/controller-frontend.php */
$use_default_css = apply_filters( 'tablepress_use_default_css', true );
$custom_css = TablePress::$model_options->get( 'custom_css' );
$use_custom_css = ( TablePress::$model_options->get( 'use_custom_css' ) && '' !== $custom_css );
$use_custom_css_file = ( $use_custom_css && TablePress::$model_options->get( 'use_custom_css_file' ) );
/**
* Filters the "Custom CSS" version number that is appended to the enqueued CSS files
*
* @since 1.0.0
*
* @param int $version The "Custom CSS" version.
*/
$custom_css_version = (string) apply_filters( 'tablepress_custom_css_version', TablePress::$model_options->get( 'custom_css_version' ) );
$tablepress_css = TablePress::load_class( 'TablePress_CSS', 'class-css.php', 'classes' );
// Determine Default CSS URL.
$rtl = ( is_rtl() ) ? '-rtl' : '';
$unfiltered_default_css_url = plugins_url( "css/build/default{$rtl}.css", TABLEPRESS__FILE__ );
/**
* Filters the URL from which the TablePress Default CSS file is loaded.
*
* @since 1.0.0
*
* @param string $unfiltered_default_css_url URL of the TablePress Default CSS file.
*/
$default_css_url = apply_filters( 'tablepress_default_css_url', $unfiltered_default_css_url );
$use_custom_css_combined_file = ( $use_default_css && $use_custom_css_file && ! SCRIPT_DEBUG && ! is_rtl() && $unfiltered_default_css_url === $default_css_url && $tablepress_css->load_custom_css_from_file( 'combined' ) );
if ( $use_custom_css_combined_file ) {
$custom_css_combined_url = $tablepress_css->get_custom_css_location( 'combined', 'url' );
// Need to use 'tablepress-default' instead of 'tablepress-combined' to not break existing TablePress Extensions.
wp_enqueue_style( 'tablepress-default', $custom_css_combined_url, array(), $custom_css_version );
} else {
$custom_css_dependencies = array();
if ( $use_default_css ) {
wp_enqueue_style( 'tablepress-default', $default_css_url, array(), TablePress::version );
// Add dependency to make sure that Custom CSS is printed after Default CSS.
$custom_css_dependencies[] = 'tablepress-default';
}
$use_custom_css_minified_file = ( $use_custom_css_file && ! SCRIPT_DEBUG && $tablepress_css->load_custom_css_from_file( 'minified' ) );
if ( $use_custom_css_minified_file ) {
$custom_css_minified_url = $tablepress_css->get_custom_css_location( 'minified', 'url' );
wp_enqueue_style( 'tablepress-custom', $custom_css_minified_url, $custom_css_dependencies, $custom_css_version );
return;
}
$use_custom_css_normal_file = ( $use_custom_css_file && $tablepress_css->load_custom_css_from_file( 'normal' ) );
if ( $use_custom_css_normal_file ) {
$custom_css_normal_url = $tablepress_css->get_custom_css_location( 'normal', 'url' );
wp_enqueue_style( 'tablepress-custom', $custom_css_normal_url, $custom_css_dependencies, $custom_css_version );
return;
}
if ( $use_custom_css ) {
// Get "Custom CSS" from options, try minified Custom CSS first.
$custom_css_minified = TablePress::$model_options->get( 'custom_css_minified' );
if ( ! empty( $custom_css_minified ) ) {
$custom_css = $custom_css_minified;
}
/**
* Filters the "Custom CSS" code that is to be loaded as inline CSS.
*
* @since 1.0.0
*
* @param string $custom_css The "Custom CSS" code.
*/
$custom_css = apply_filters( 'tablepress_custom_css', $custom_css );
if ( ! empty( $custom_css ) ) {
// wp_add_inline_style() requires a loaded CSS file, so we have to work around that if "Default CSS" is disabled.
if ( $use_default_css ) {
// Handle of the file to which the <style> shall be appended.
wp_add_inline_style( 'tablepress-default', $custom_css );
} else {
add_action( 'wp_head', array( $this, '_print_custom_css' ), 8 ); // Priority 8 to hook in right after WP_Styles has been processed.
}
}
}
}
}i have the same issue, and it works for me. you can test it and hope Tobias will mod. the file
- This reply was modified 17 hours, 50 minutes ago by spielo.
Hi!
Thanks for your post and sorry for the trouble!
This does indeed sound as if the TablePress CSS files are no longer loaded, maybe due to some conditions not being met.
The
<tr class="row-1">
code is however correct.The suggestion by spielo might work, but I do not recommend this at the moment. Much rather, we should try finding out the actual cause for this problem. For that, please post a link to the page with the table where this problem happens, so that I can take a direct look. Thanks! (You can also use the “Send us an email! button at the bottom of https://tablepress.org/pricing/.)
Best wishes,
TobiasHello Tobias, yes I’d rather not go for the Spielo solution but rely on the official author ??
You can view the new Tablepress here on this page (applied to the 2nd table), and compare it with my old CSS. I wish to retain the header + odd rows background, the pagination buttons, and the search field right alignment above the tables container.
Looking forward to your reply.
Hi,
thanks for the links! It does indeed look like the new TablePress CSS files are not loaded on your site, for some reason. To debug this further, can you please get in touch via email, via the mentioned button from above?
Regards,
Tobias
- You must be logged in to reply to this topic.