Support » Plugin: TablePress » Hide last column on all tables via backend

  • Resolved pcuniverse

    (@pcuniverse)



    Hello,

    I have 300 tables and I need to hide the last column on each one of them. I need them to not be outputted at all in the HTML either, so I can’t use CSS. The tables have different column numbers, so I can’t use shortcode parameters either (I want backwards comptability, so I can easily revert).

    Is it possible to create a function in PHP perhaps that can prevent the last column in all tables from being outputted? I can get a developer to write the function if it’s complex, I just need some hints into the right direction to make it easier. If it can be done via Tablepress itself, I can do it as well.

    Thank you very much for making this awesome plugin!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your question, and sorry for the trouble.

    That’s an interesting question…
    This PHP code should do that, just add it to your theme’s “functions.php” file (or into a small custom plugin):

    add_filter( 'tablepress_table_render_options', 'pcuniverse_tablepress_hide_last_column', 10, 2 );
    function pcuniverse_tablepress_hide_last_column( $render_options, $table ) {
      $last_column = (string) count( $table['data'][0] );
    
      if ( '' === $render_options['hide_columns'] ) {
        $render_options['hide_columns'] = $last_column;
      } else {
        $render_options['hide_columns'] .= ",{$last_column}";
      }
    
      return $render_options;
    }

    (Note that I didn’t test the code.)

    Regards,
    Tobias

    Works perfectly – thank you so much!

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! 🙂 Good to hear that this helped!

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide last column on all tables via backend’ is closed to new replies.