Title: Inserting shortcodes in head code
Last modified: December 9, 2016

---

# Inserting shortcodes in head code

 *  Resolved [Muuski](https://wordpress.org/support/users/muuski/)
 * (@muuski)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/inserting-shortcodes-in-head-code/)
 * I noticed there is a thread around running PHP code using this plugin:
    [https://wordpress.org/support/topic/inserting-php/](https://wordpress.org/support/topic/inserting-php/)
 * And I agree with the security concerns around doing that. However, for my needs
   I want to run shortcodes inside the inserted head code.
 * For more clarity, my use case is going to look something like this:
 *     ```
       <script>
           (function (param) {
               alert(param);
           })("[ShortCode]");
       </script>
       ```
   
 * I cannot see how exposing shortcodes in the head would be any more of a security
   concern than doing the same thing in the body.
 * I took a look into the code last night and it seems like this change is simply
   to use do_shortcode:
 *     ```
       if(!empty($addtoheadcontent)){
       	echo stripslashes_deep(do_shortcode($addtoheadcontent));
       }
       ```
   
 * I tried this change and the above example would alert: “[ShortCode]”
 * Maybe I needed to make the change elsewhere, or there is something else halting
   this from happening?
 * Assuming I can get it to work, is there any way we can get this supported? I’m
   sure I’m not the only one who wants dynamic Javascript and I’ve seen at least
   one other plugin that promises to be “shortcode enabled” but does not have per
   page editing.
    -  This topic was modified 9 years, 5 months ago by [Muuski](https://wordpress.org/support/users/muuski/).
      Reason: Formatting

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

 *  Plugin Author [Erikvona](https://wordpress.org/support/users/erikvona/)
 * (@erikvona)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/inserting-shortcodes-in-head-code/#post-8534594)
 * I will look into this. I’m planning to release an update this to next week with
   some bug fixes, and will look if I can include this.
 * I think your code will work, except that the do_shortcode should be outside, 
   and not inside the stripslashes:
 *     ```
       if(!empty($addtoheadcontent)){
       	echo do_shortcode(stripslashes_deep($addtoheadcontent));
       }
       ```
   
 * Else, you will run into errors with slashes being removed in the code your shortcode
   places, and your shortcode not working if there are any characters in it that
   should be escaped.
    -  This reply was modified 9 years, 5 months ago by [Erikvona](https://wordpress.org/support/users/erikvona/).
      Reason: mistype
 *  Thread Starter [Muuski](https://wordpress.org/support/users/muuski/)
 * (@muuski)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/inserting-shortcodes-in-head-code/#post-8536929)
 * That worked as expected. It probably wasn’t working before because I might not
   have been registering my shortcode correctly.
 * Thank you for the quick reply. I’m looking forward to seeing if this makes it
   into the update you’re planning.

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

The topic ‘Inserting shortcodes in head code’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/per-page-add-to.svg)
 * [Per page add to head](https://wordpress.org/plugins/per-page-add-to/)
 * [Support Threads](https://wordpress.org/support/plugin/per-page-add-to/)
 * [Active Topics](https://wordpress.org/support/plugin/per-page-add-to/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/per-page-add-to/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/per-page-add-to/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Muuski](https://wordpress.org/support/users/muuski/)
 * Last activity: [9 years, 5 months ago](https://wordpress.org/support/topic/inserting-shortcodes-in-head-code/#post-8536929)
 * Status: resolved