The proper way to enqueue a script is as follows:
function mathJax_scripts() {
wp_enqueue_script( 'mathjax-js', http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML', array(), '2.7.1', false );
}
add_action( 'wp_enqueue_scripts', 'mathJax_scripts' );
I added the version number (2.7.1) and I flipped the final parameter to ‘false’ – that last parameter asks ‘add script to footer?’, true means yes, false means no.
Then you’ll want to add the inline code into the wp_head()
:
function mathJax_inlineScript() {
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX", "output/HTML-CSS"],
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true
},
"HTML-CSS": { availableFonts: ["TeX"] }
});
</script>
<?php }
add_action( 'wp_head', 'mathJax_inlineScript' , 999 );
In the add action I’ve set it to 999 – you can adjust and fine tune that to get the inline script to appear where you want it to in the wp_head()
.
Hope that helps.