5
$\begingroup$

I usually instert my CDF demonstrations in my WordPress site with the WolframCDF plugin v.2.1.

It worked fine till a couple of days ago.

But, after the recent (automatic) upgrade of WordPress from 4.0.0 to 4.0.1 that doesn't work anymore. The CDF is no more shown in the page, just the html code calling it.

Is anyone else experiencing this problem?

I'm afraid I'll have to downgrade to WordPress 4.0.0 (not so easy) or wait for the developer of the WolframCDF plugin to adjust it to the new version of WP.

At the moment my website (www.lucamoroni.it) heavily based on CDF simulations is totally useless!

But maybe there could be some workaround (i.e. modify manually some configuration file) to fix things (at least temporarily).

Any help? (any dirty trick?)

$\endgroup$
  • $\begingroup$ Just to be clear; you are using the shortcode to display CDFs. Does the shortcode not do anything (does it appear on the website?) or does it output non-working code? $\endgroup$ – C. E. Nov 22 '14 at 15:21
  • $\begingroup$ @Pickett I'm not using shortcodes. The CDF is loaded in my MEDIA folder and the link is something like http://<mywebsite>/wp-content/uploads/2014/11/WaveMotion.cdf. The output in the page is not the one of the CDF player but a text string like [WolframCDF source=”<mywebsite>/wp-content/uploads/2014/11/WaveMotion.cdf” width=”939″ height=”1014″ altimage=”http://<mywebsite>/wp-content/uploads/2014/11/WaveMotion.png” altimagewidth=”939″ altimageheight=”1014″] $\endgroup$ – Luca M Nov 22 '14 at 15:31
  • $\begingroup$ Exactly, that last part is known as a "shortcode". Try adding code-tags in text mode as is suggested here. $\endgroup$ – C. E. Nov 22 '14 at 15:49
  • 1
    $\begingroup$ THANKS!!! Inserting the <code></code> tags around the [WolframCDF source= .... ] statement worked! :). You should publish this as an answer. It might help many other WordPress users... $\endgroup$ – Luca M Nov 22 '14 at 17:23
  • $\begingroup$ Luca, I've written my own WordPress plugin now that does CDF embedding and other things, if you're interested: Mathematica Toolbox. $\endgroup$ – C. E. Jul 10 '15 at 4:39
10
$\begingroup$

Update

The new plugin Mathematica Toolbox can embed CDFs and do many other things. The official plugin is still not working.


The problem is that whoever wrote the Wordpress plugin didn't use the official API to parse the CDF shortcode. The CDF plugin is essentially saying "right before the content is presented, modify it using function parseContent" (add_filter('the_content', array($wolframCDF, 'parseContent'));). The function parseContent uses regular expressions to find the shortcode, parse its attributes and replace it with the CDF code. It does not work in Wordpress 4.01 because the shortcode is modified (prettified for presentation) before it reaches parseContent, and so is not recognized by the regular expression.

In order to make it work WRI needs to update the plugin and use the official shortcode API, i.e. parse the shortcode attributes by writing

function parseContent( $atts ) {
    // Do stuff with the given attributes
}
add_shortcode('WolframCDF', 'parseContent');

which is both simpler and future proof.

In the meantime there is a fix that tells Wordpress not to touch the shortcode, which means it will still match the regular expressions. This is to go into text mode and wrap the shortcode with a code tag, i.e.

<code>[WolframCDF attributes]</code>

Note that you have to do it in text mode, you cannot use the visual mode. Using the <pre> tag should also work.

Another way (which I can not test, because I don't have Wordpress installed on this computer) is to go to wp-content/themes/your_theme/ and open functions.php. Add the following line to the top of this file:

apply_filters('run_wptexturize', false);

This should disable wp_texturize and thus make the CDF shortcode work again. Note that wp_texturize does many good things, so it's better to fix the plugin instead of turning off wp_texturize. But if you have many posts with the CDF shortcode in them, then updating each one may take some time and this could be a more attractive option.

$\endgroup$
  • 1
    $\begingroup$ Perfect and clear explanation. Now I know something more about the problem I had. Furthermore it spared me from the long and risky process of downgrading the WP version. $\endgroup$ – Luca M Nov 22 '14 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.