Title: Adding HTML to tables
Last modified: August 21, 2016

---

# Adding HTML to tables

 *  Resolved [Andrew Leonard](https://wordpress.org/support/users/andrewleonard/)
 * (@andrewleonard)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/adding-html-to-tables/)
 * Hi
    If you look at this page: [http://www.andrew-leonard.co.uk/wordpress/ferns-2/growing/spore-exchange/spore-list/](http://www.andrew-leonard.co.uk/wordpress/ferns-2/growing/spore-exchange/spore-list/)
   You will see that the first entry “Acrostichum aureum” has a HTML link to do 
   a Google search. I have put the HTML in the cell. My question is, is there any
   way of arranging for the HTML code to be added to each cell without having to
   put it in myself – rather in the same way that you can add a CSS style to a whole
   row with one command in “Plugin Options”
 * [https://wordpress.org/plugins/tablepress/](https://wordpress.org/plugins/tablepress/)

Viewing 15 replies - 1 through 15 (of 34 total)

1 [2](https://wordpress.org/support/topic/adding-html-to-tables/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/adding-html-to-tables/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/adding-html-to-tables/page/2/?output_format=md)

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/adding-html-to-tables/#post-4970127)
 * Hi,
 * thanks for your question, and sorry for the trouble.
 * Well, technically, it is possible to add this HTML automatically, but it’s not
   as easy as using “Custom CSS”. The reason simply is that this HTML is part of
   the table content, whereas the CSS is “just” the styling applied to the content.
   
   So, to add that HTML automatically, you would need to use programming. In particular,
   you would need to use PHP code to hook into one of the available plugin filter
   hooks like “tablepress_cell_content” and then add the HTML there.
 * Regards,
    Tobias
 *  Thread Starter [Andrew Leonard](https://wordpress.org/support/users/andrewleonard/)
 * (@andrewleonard)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/adding-html-to-tables/#post-4970140)
 * I am out of my depth here
    I can program a bit in php and have created a function:
   function Google_Wrap($tablepress_cell_content) { $temp=$tablepress_cell_content;
   $tablepress_cell_content = ““.$temp.”“; return $tablepress_cell_content; } Now
   I am lost… I would somehow have to execute this function on every cell in a specific
   row in a specific table…
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/adding-html-to-tables/#post-4970154)
 * Hi,
 * that’s a great start already.
    You’ll now just have to add some extra checks (
   i.e. whether you are dealing with the desired table and row), by using the other
   parameters that this filter hooks can use:
 *     ```
       add_filter( 'tablepress_cell_content', 'Google_Wrap', 10, 4 );
       function Google_Wrap( $tablepress_cell_content, $table_id, $row_number, $column_number ) {
         ...
       }
       ```
   
 * If you are in the desired table/row/column, you make the necessary modifications,
   and otherwise, you just return the unmodified cell content.
 * Regards,
    Tobias
 *  Thread Starter [Andrew Leonard](https://wordpress.org/support/users/andrewleonard/)
 * (@andrewleonard)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/adding-html-to-tables/#post-4970157)
 * add_filter( ‘tablepress_cell_content’, ‘Google_Wrap15’, 10, 4 );
    function Google_Wrap15(
   $tablepress_cell_content, $table_id, $row_number, $column_number ) { if ($table_id
   ==15) if ($column_number==2) { $temp=$tablepress_cell_content; $tablepress_cell_content
   = ““.$temp.”“; } return $tablepress_cell_content; } Is that it? – where do I 
   put this code? are all the variables $tablepress_cell_content, etc setup already?
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/adding-html-to-tables/#post-4970159)
 * Hi,
 * yes, almost. Just be careful with the braces:
 *     ```
       add_filter( 'tablepress_cell_content', 'Google_Wrap15', 10, 4 );
       function Google_Wrap15( $tablepress_cell_content, $table_id, $row_number, $column_number ) {
         if ($table_id==15) {
           if ($column_number==2) {
             $temp=$tablepress_cell_content;
             $tablepress_cell_content = "".$temp."";
           }
         }
         return $tablepress_cell_content;
       }
       ```
   
 * Just put this into the “functions.php” in your theme or a small new plugin file,
   and you should be good to go 🙂
 * Regards,
    Tobias
 *  Thread Starter [Andrew Leonard](https://wordpress.org/support/users/andrewleonard/)
 * (@andrewleonard)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/adding-html-to-tables/#post-4970161)
 * I put the code into functions.php in my child theme and I left out a brace and
   I got an error message which I have now corrected so it is being “triggered” –
   but nothing is happening!
    Have I misunderstood something?
 *  Thread Starter [Andrew Leonard](https://wordpress.org/support/users/andrewleonard/)
 * (@andrewleonard)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/adding-html-to-tables/#post-4970163)
 * It is working!
    I thought I would see the code in “TablePress” – that is what
   I did not understand – but it adds the code when you load the page(?) -I am not
   sure but it is working very well when I look at the page
 * So thank you – I have enjoyed being your apprentice!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/adding-html-to-tables/#post-4970169)
 * Hi,
 * this code is basically running whenever the HTML output of the table is being
   regenerated, but you won’t see these changes on the “Edit” screen.
    Note that
   code changes will only take effect after the internal table cache is cleared,
   i.e. after you wait for 12 hours, or each time after saving the table.
 * Regards,
    Tobias
 *  Thread Starter [Andrew Leonard](https://wordpress.org/support/users/andrewleonard/)
 * (@andrewleonard)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/adding-html-to-tables/#post-4970172)
 * If you look at my table, some of the Fern Names have a code after them in the
   form of (Z3-8). I have just amended the function to strip that off, if it exists,
   so that Google just concentrates on the Fern Name.
    Maybe I have misunderstood
   but it seems to have picked up the amended function
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/adding-html-to-tables/#post-4970175)
 * Hi,
 * I’m not sure what you mean here.
    If the output at [http://www.andrew-leonard.co.uk/wordpress/ferns-2/growing/spore-exchange/spore-list/](http://www.andrew-leonard.co.uk/wordpress/ferns-2/growing/spore-exchange/spore-list/)(
   when you are logged-in into WordPress) is not what you expect, your PHP code 
   is not working properly.
 * Regards,
    Tobias
 *  Thread Starter [Andrew Leonard](https://wordpress.org/support/users/andrewleonard/)
 * (@andrewleonard)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/adding-html-to-tables/#post-4970191)
 * It behaves differently when I am logged in to when I am logged out
    It only picks
   up my amended code when I log in Does this make sense to you? This is the amended
   code: add_filter( ‘tablepress_cell_content’, ‘Google_Wrap15’, 10, 4 ); function
   Google_Wrap15( $tablepress_cell_content, $table_id, $row_number, $column_number){
   if ($table_id==15) { if ($column_number==2 or $column_number==4) { $x=strpos(
   $tablepress_cell_content, ‘(‘); if ($x==0) {$temp=$tablepress_cell_content;} 
   else {$temp=substr($tablepress_cell_content,0,$x);} $tablepress_cell_content 
   = ““.$tablepress_cell_content.”“; } } return $tablepress_cell_content;
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/adding-html-to-tables/#post-4970193)
 * Hi,
 * yes, that makes sense 🙂 The reason is what I described above, the table output
   caching.
 * After editing the PHP code, simply save the table on the “Edit” to flush the 
   cache (or wait 12 hours, which is the cache period). After that, you will see
   the same output when logged-in and when logged-out.
 * Regards,
    Tobias
 *  Thread Starter [Andrew Leonard](https://wordpress.org/support/users/andrewleonard/)
 * (@andrewleonard)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/adding-html-to-tables/#post-4970199)
 * Yes you did try to tell me this but I did not understand
    I “saved” the table
   and now it works when I am logged out
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/adding-html-to-tables/#post-4970201)
 * Hi,
 * very nice! Great to hear that everything is working now! 🙂
 * Best wishes,
    Tobias
 *  [ziyaindia78](https://wordpress.org/support/users/ziyaindia78/)
 * (@ziyaindia78)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/adding-html-to-tables/#post-4970440)
 * Dear Tobias,
 * Please check following URL
 * [http://www.gamesage.co.uk/?page_id=8](http://www.gamesage.co.uk/?page_id=8)
 * I need to display image into “Box Art” and “Buy Link”.
 * I want to update all values for above 2 columns.
 * Could you please tell me how I need to update “add_filter( ‘tablepress_cell_content’,‘
   Google_Wrap15’, 10, 4 )” for my requirement.
 * Thanks,
    Ziya

Viewing 15 replies - 1 through 15 (of 34 total)

1 [2](https://wordpress.org/support/topic/adding-html-to-tables/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/adding-html-to-tables/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/adding-html-to-tables/page/2/?output_format=md)

The topic ‘Adding HTML to tables’ is closed to new replies.

 * ![](https://ps.w.org/tablepress/assets/icon.svg?rev=3192944)
 * [TablePress - Tables in WordPress made easy](https://wordpress.org/plugins/tablepress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/tablepress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/tablepress/)
 * [Active Topics](https://wordpress.org/support/plugin/tablepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/tablepress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/tablepress/reviews/)

 * 34 replies
 * 3 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/adding-html-to-tables/page/3/#post-4970459)
 * Status: resolved