/** * Funzione per aggiungere codice javascript nel footer di * wordpress con caricamento asincrono seguendo metodo google * * @return void */ function setJavascriptPlatform() { // Se ho già inserito il codice javascript nella sezione footer // esco dalla funzione altrimenti setto la variabile e continuo if (self::$JavascriptPlatform) { return; } else { self::$JavascriptPlatform = true; } // Codice javascript per il rendering dei componenti google platform // ad esempio richiamare questo script per i bottoni di hangouts $javascript = '<script type="text/javascript">'; $javascript .= "(function(){"; $javascript .= "var po=document.createElement('script');po.type='text/javascript';po.async=true;"; $javascript .= "po.src='https://apis.google.com/js/platform.js';"; $javascript .= "var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(po,s);"; $javascript .= "})();"; $javascript .= "</script>" . "\n"; // Esecuzione echo su footer del codice javascript generato echo $javascript; }
/** * Function to add javascript code in the footer of wordpress * with asynchronous loading method according to google */ function setJavascriptPlatform() { // If you've already entered the Javascript code in the footer section // leave the partition function otherwise the variable and constant if (self::$JavascriptPlatform) { return; } else { self::$JavascriptPlatform = true; } // Javascript code to render the google platform components // for example call this script for the buttons hangouts $javascript = '<script type="text/javascript">'; $javascript .= "(function(){"; $javascript .= "var po=document.createElement('script');po.type='text/javascript';po.async=true;"; $javascript .= "po.src='https://apis.google.com/js/platform.js';"; $javascript .= "var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(po,s);"; $javascript .= "})();"; $javascript .= "</script>" . "\n"; // Running echo on the footer of the javascript code generated // This code is added to a single block together with other functions echo $javascript; }