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

    (@tobiasbg)

    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

    (@andrewleonard)

    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 TobiasBg

    (@tobiasbg)

    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

    (@andrewleonard)

    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 TobiasBg

    (@tobiasbg)

    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

    (@andrewleonard)

    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

    (@andrewleonard)

    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 TobiasBg

    (@tobiasbg)

    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

    (@andrewleonard)

    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 TobiasBg

    (@tobiasbg)

    Hi,

    I’m not sure what you mean here.
    If the output at https://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

    (@andrewleonard)

    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 TobiasBg

    (@tobiasbg)

    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

    (@andrewleonard)

    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 TobiasBg

    (@tobiasbg)

    Hi,

    very nice! Great to hear that everything is working now! ??

    Best wishes,
    Tobias

    Dear Tobias,

    Please check following URL

    https://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)
  • The topic ‘Adding HTML to tables’ is closed to new replies.