Title: Convert HTML Script to Shortcode
Last modified: March 13, 2021

---

# Convert HTML Script to Shortcode

 *  [xscorpionx](https://wordpress.org/support/users/xscorpionx/)
 * (@xscorpionx)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/convert-html-script-to-shortcode/)
 * I want to convert this code into a shortcode, I have seen that an example comes
   but when I put it it does not work. How can this script be converted into a shortcode
   from code snippets?
 *     ```
       <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>
       ```
   
    -  This topic was modified 5 years, 3 months ago by [xscorpionx](https://wordpress.org/support/users/xscorpionx/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [ranazaman07](https://wordpress.org/support/users/ranazaman07/)
 * (@ranazaman07)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/convert-html-script-to-shortcode/#post-14292636)
 * [https://www.megowords.com/wp-admin/admin.php?page=add-new-auction](https://www.megowords.com/wp-admin/admin.php?page=add-new-auction)
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/convert-html-script-to-shortcode/#post-14751650)
 * I’m not 100% sure what you are going for, but you should just be able to wrap
   it in a shortcode function:
 *     ```
       add_shortcode( 'banner_script', function () {
       	ob_start(); ?>
   
       <!-- put your code here -->
   
       	<?php
       	return ob_get_clean();
       } );
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Convert HTML Script to Shortcode’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

## Tags

 * [html](https://wordpress.org/support/topic-tag/html/)
 * [script](https://wordpress.org/support/topic-tag/script/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 2 replies
 * 3 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [4 years, 10 months ago](https://wordpress.org/support/topic/convert-html-script-to-shortcode/#post-14751650)
 * Status: not a support question