Trying to load CSS file conditionally – only for specific pages with the following:

add_filter('tablepress_use_default_css', 'tablepress_css_conditional_load');
function tablepress_css_conditional_load($load) {
return ((!is_page(array( 229, 9 ))) ? false : $load);

For some reason it is not working. To make sure that there is no mistake in the IDs I replaced ! is_page( array( 229, 9 ) ) with ! is_page() and with ! is_single() but still it is not working. Deactivated other plugins, changed theme, still nothing. The CSS name is verified with the plugin author. When the above part is replaced with is_single() the code works in a way that lets the CSS load for any page – not for posts. However the point is to load only for the named pages. Which is the correction needed?

  • is_single() is working correctly developer.wordpress.org/reference/functions/is_single – Stefano Tombolini Jan 12 at 18:12
  • @StefanoTombolini Yes, but the point is to have the css file loading only for the specific pages 229 and 9. – Michael Jan 12 at 18:39
  • Do !is_single / !is_page work as expected? It should load only on posts / pages. – Stefano Tombolini Jan 12 at 19:41
  • @StefanoTombolini No, they do not work at all: if I use either !is_single or !is_page the css file is loading both for pages and posts. – Michael Jan 13 at 13:48

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.