0

I want to use a php helper to publish shortcodes to my WP page. This will eventually include variables, but for now I just want the shortcodes to parse when the page renders.

I have the below PHP which correctly renders a table for my page...

<?
require_once( 'http://mywebsite.com/wp-load.php' );

$therm_sponsor = "[thermometer raised=0 target=1000]";
$therm_expenses = "[thermometer raised=0 target=1000]";

echo '<table>';
echo '<tbody>';
echo '<tr align="center" valign="middle">';
echo "<td>". do_shortcode($therm_sponsor) ."</td>";
echo "<td>". do_shortcode($therm_expenses) ."</td>";
echo '</tr>';
echo '<tr align="center" valign="middle">';
echo '<td>Funds Raised </td>';
echo '<td>Expenses Covered </td>';
echo '</tr>';
echo '</tbody>';
echo '</table>';

?>

I then include this on my post with the plugin Shortcode Exec, which itself uses a shortcode to include PHP in the page body.

However, when I load the page, I see this table, which includes a text version of the two shortcodes above. In other words, php is correctly outputting the html, but the shortcodes included are not being seen as shortcodes by Wordpress.

FYI the two shortcodes are for a plugin for thermometer tracking donations.

While this might seem like a roundabout way to do this, the main reason is so I can later use php to add dynamic variables to the thermometer shortcodes.

For clarity, here are the steps I use...

  • Include the PHP helper with PHP Exec plugin
  • Call that on my page with PHP Exec shortcode
  • Loading the page indeed renders out my html table from the php helper, but the two shortcodes within the table are not seen by Wordpress as shortcodes, and render at text

How can I make the second layer of shortcodes parse through Wordpress?

Edit: Code updated. Error Fatal error: Call to undefined function do_shortcode()

1 Answer 1

2

If i correctly understand your question, than you need something like this:--

Replace your following lines with this:-

echo "<td>". do_shortcode($therm_sponsor) ."</td>";
echo "<td>". do_shortcode($therm_expenses) ."</td>";

This will do action according to your shortcode..


If your helper file is outside the WordPress than you need to add require_once( 'YOUR_WORDPRESS_DIRECTORY_PATH/wp-load.php' ); at the very top of your helper file...

After including this file in your helper, you can use any function of WordPress in your helper...

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks:) but do_shortcode produces the error Fatal error: Call to undefined function do_shortcode(). Is this because my PHP helper is outside of the Wordpress ecosystem?
Ah I was close... I tried to include functions.php. Although when I do as you say I still get the function error.
Updated: Same error Fatal error: Call to undefined function do_shortcode() I double checked the path.
Ok I got it to work. I moved the 'require_once' from the PHP helper to the PHP Exec plugin above include 'http://mywebsite.com/pathto/helper.php';
Ok no problem...I think there was little path problems... By the way its working now...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.