I want to convert this code into a shortcode from the Code Snippets plugin, I have seen an example come up but when I put it it does not work, the example is the following:
add_shortcode( 'shortcode_name', function () { $ out = '<p>write your HTML shortcode content here</p>'; return $ out; } );
I want to convert the following code to rotate banners:
<script> rnd.today=new Date(); rnd.seed=rnd.today.getTime(); function rnd() { rnd.seed = (rnd.seed*9301+49297) % 233280; return rnd.seed/(233280.0); } function rand(number) { var result = Math.floor(rnd() * number); if (!result) result = 0; return result } var bannerimgs = new Array("a.jpg", "b.jpg"); var bannerlnks = new Array("a.com", "b.com"); var banneralt = new Array("a", "b"); var rotatorHtml = ""; var endJs = ""; for(var img in bannerimgs){ var thisImg = new Image(); thisImg.src = bannerimgs[img]; } var bannerimgCt = 2; var bannercurrentAd = rand(bannerimgCt); var openlink = ""; var bannerbanner = document.getElementById('banner'); var bannerlink = document.getElementById('banneradLink'); if(bannerlnks[bannercurrentAd] != ""){ rotatorHtml += '<a href="' + bannerlnks[bannercurrentAd] + '" id="banneradLink" target="_blank">'; endJs = "</a>"; } rotatorHtml += '<img src="' + bannerimgs[bannercurrentAd] + '" alt = "' + banneralt[bannercurrentAd] + '" id="bannerbanner">' + endJs; document.getElementById("banner_div").innerHTML = rotatorHtml; </script>
How can this script be converted to a shortcode? I have replaced what it says but errors appear, then I do something wrong. How can this script be converted to a shortcode? Do you know any other way?