Any way to perform math on the output of a shortcode in table?

Hello there! I’m a bit of a WordPress idiot, and I’m curious if this little project of mine is possible. I’m trying to build a table that uses the daily updated price of precious metals supplied from a shortcode called \[gold\_price\]. The value would then be changed based on grade of metal with a little multiplication.

IE:

\[gold\_bid\]x1=24kt price

\[gold\_bid\]x0.91=20kt price

\[gold\_bid\]x0.82=21kt price

​

I tried using a table plugin that describes itself as being capable of math operators in cells, called Tablepress. This doesn’t seem to be the case for any value let alone the output of the shortcode. Does anyone have a Table plug in that might work for this solution?

Thank you!

3 Comments
  1. Not the way you’re trying to do it. It’d generally require some custom coding to get the end result that you want, and since shortcodes does not really interact outside of its own scope, it’s not possible the way you’re currently trying to do it.

  2. Table Press can do math, I used it some time ago for a website. Just can’t remeber off the top of my head how to configure it. But I’ll try to see if I can build you a table based on your examples above and give you an import file in a couple of hours.

  3. You could alter the following and duplicate it 3 times for the various values

    `function reddit_gold_price_shortcode( $atts ) {`
    `$atts = shortcode_atts( array(`
    `’amount’ => false,`
    `), $atts );`
    `$amount = floatval( $atts[‘amount’] );`
    `if ( $amount !== false ) {`
    `$gold_price = $amount * 0.82;`
    `return ‘<strong>Gold Price:</strong> $’ . number_format( $gold_price, 2 );`
    `} else {`
    `return ‘<strong>Error:</strong> Please specify a valid amount.’;`
    `}`
    `}`
    `add_shortcode( ‘gold_price’, ‘reddit_gold_price_shortcode’ );`
    `// example usage [gold_price amount=24]`

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer