Trying to connect to wordpress MathJax and configure it. Connecting MathJax did not cause any problems. But I can not connect an additional script to configure MathJax. I add to the functions.php file a code for loading a local script containing the settings:

wp_enqueue_script( 'MathJaxConfiguration', get_template_directory_uri() . '/js/MathJaxCfg.js', null, false, false ); 

In the browser, this script is loaded with the type="text/javascript" attribute, but for MathJax to hook this script the type = attribute must contain the text/x-mathjax-config parameter. To replace the attribute used filter

 add_filter( 'script_loader_tag', 'filter_script_MathJax', 10, 3 ); function filter_script_MathJax( $tag, $handle, $src ){ if ( 'MathJaxConfiguration' === $handle ) { return str_replace( 'text/javascript', 'text/x-mathjax-config', $tag ); } return $tag; } 

The attribute successfully changes, but the script is not executed. In the browser inspector it is displayed. Added to the beginning of the file MathJaxCfg.js alert, with type="text/javascript" alert fulfills, with text/x-mathjax-config not. How to make it all work?

    1 answer 1

    I solved the problem by rereading the MathJax documentation. In wordpress, just use the construction

     wp_enqueue_script( 'MathJax', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML,http://localhost/wordpress/wp-content/themes/имя_ΠΏΠ°ΠΏΠΊΠΈ_с_Ρ‚Π΅ΠΌΠΎΠΉ/js/MathJaxCfg.js', null, false, false ); 

    It was necessary to add http://localhost/wordpress/wp-content/themes/имя_ΠΏΠ°ΠΏΠΊΠΈ_с_Ρ‚Π΅ΠΌΠΎΠΉ/js/MathJaxCfg.js' -content http://localhost/wordpress/wp-content/themes/имя_ΠΏΠ°ΠΏΠΊΠΈ_с_Ρ‚Π΅ΠΌΠΎΠΉ/js/MathJaxCfg.js' - the full path to the settings file on the server. Also, the path to the settings file must be specified at the end of the MathJaxCfg.js file using the following construction MathJax.Ajax.loadComplete('http://localhost/wordpress/wp-content/themes/имя_вашСй_Ρ‚Π΅ΠΌΡ‹/js/MathJaxCfg.js');