Title: creating shortcode that contains code?
Last modified: May 8, 2020

---

# creating shortcode that contains code?

 *  [thetoolman123](https://wordpress.org/support/users/thetoolman123/)
 * (@thetoolman123)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/creating-shortcode-that-contains-code/)
 * Hi there,
 * Please can you tell me if it is possible to create a [shortcode] that contains
   some HTML/JS?
 * I basically need to insert some Adsense code into each of my posts but don’t 
   want to keep pasting the code.
 * Is this possible?
 * Thanks

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

 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/creating-shortcode-that-contains-code/#post-12793254)
 * [@thetoolman123](https://wordpress.org/support/users/thetoolman123/)
 * You can place adsense code in the template that loads your pages/posts.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/creating-shortcode-that-contains-code/#post-12793554)
 * Shortcodes can have the form of
    `[example]Content passed to shortcode handler[/
   example]`
 * The shortcode handler can take that content and wrap it in `<script>` tags before
   returning the proper JS code. AFAIK the editor will not corrupt code passed in
   this manner, but you’ll need to confirm this for yourself.
 * Inserting code onto a page is better handled from an action hook somewhere or
   as corrinarusso suggests, outputting from a template. The proper way to introduce
   JS code is through `wp_enqueue_script()`, but that does at times have its drawbacks.
 *  Thread Starter [thetoolman123](https://wordpress.org/support/users/thetoolman123/)
 * (@thetoolman123)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/creating-shortcode-that-contains-code/#post-12795469)
 * Thanks for the replies.
 * How do I go about actually creating a shortcode?
 * I could paste in may adsense code each time I make a post, but it would be easier
   to type or paste [adsense-shortcode] for example each time I make a post.
 * I have a template already, but I want the adsense code after the first paragraph
   of the post so I would have to do it manually.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/creating-shortcode-that-contains-code/#post-12797323)
 * Please see the Shortcode API:
    [https://codex.wordpress.org/Shortcode_API](https://codex.wordpress.org/Shortcode_API)
 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/creating-shortcode-that-contains-code/#post-12797692)
 * [@thetoolman123](https://wordpress.org/support/users/thetoolman123/)
 * There are plugins as well if you wanted to try :
    [https://wordpress.org/plugins/wordpress-plugin-for-simple-google-adsense-insertion/](https://wordpress.org/plugins/wordpress-plugin-for-simple-google-adsense-insertion/)
 * But also pretty straight-forward how to create your own :
    [https://deliciousthemes.com/how-to-integrate-google-adsense-into-wordpress-shortcodes/](https://deliciousthemes.com/how-to-integrate-google-adsense-into-wordpress-shortcodes/)
 *  Thread Starter [thetoolman123](https://wordpress.org/support/users/thetoolman123/)
 * (@thetoolman123)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/creating-shortcode-that-contains-code/#post-12797990)
 * Thank you, I have set them up using this:
    [https://deliciousthemes.com/how-to-integrate-google-adsense-into-wordpress-shortcodes/](https://deliciousthemes.com/how-to-integrate-google-adsense-into-wordpress-shortcodes/)
 * Thank you very much!

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

The topic ‘creating shortcode that contains code?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 3 participants
 * Last reply from: [thetoolman123](https://wordpress.org/support/users/thetoolman123/)
 * Last activity: [6 years, 2 months ago](https://wordpress.org/support/topic/creating-shortcode-that-contains-code/#post-12797990)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
