user6176114 user6176114 - 2 days ago 7
PHP Question

How to multiply answer of a shortcode in PHP

I am currently working on my wordpress website and I need to multiply answer of a shortcode by 10. Here's the code I am trying -

<?php
$first_number = '[affiliates_hits for="month"]';
$second_number = 10;
$sum_total = $second_number * $first_number;
print ($sum_total);
?>


I am using a plugin called 'affiliates' and the shortcode [affiliates_hits for="month"] shows the number of visits. Currently when I echo [affiliates_hits for="month"], it shows number 8.

So the above code should result in 80, but it results 0.

Answer

Have you tried doing a do_shortcode(), since you are trying to hard code this in php.

WordPress Codex Resource: https://developer.wordpress.org/reference/functions/do_shortcode/

Comments