Title: Passing Javascript Cookie Values &#8211; Troubleshooting Needed
Last modified: August 20, 2016

---

# Passing Javascript Cookie Values – Troubleshooting Needed

 *  [siteducky](https://wordpress.org/support/users/siteducky/)
 * (@siteducky)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/passing-javascript-cookie-values-troubleshooting-needed/)
 * I am having to convert a site to WordPress, that has a javascript cookie – all
   the javascript comes from a site built in Business Catalyst. To work with this
   I added a custom field shortcode plugin and am inserting my javascript using 
   that.
 * All the basic javascript calls seem to be working but that cookie – it appears
   to set, but it does not display on the following page. I am hoping someone expert
   in javascript and WP can help me out.
 * I did review the issue with a javascript person and he said the cookie is setting,
   appears to be stored, console not throwing any errors – and we also tested for
   script call conflicts – so the only thing he could figure out was it might be
   the path and something to with how permalinks process the path.
 * Here is the URL to the page where the cookie is set:
    [http://sl-508-3.slc.westdc.net/~imacrea4/fort-myers/](http://sl-508-3.slc.westdc.net/~imacrea4/fort-myers/)
 * If you then click on one of the links in the list of communities you’ll be taken
   to the page where the cookie is received.
 * Here is a realtor site that is not on WP using the same script (with a slight
   variation only in variables) so you can see the content that should be called
   and the same script in place:
    [http://www.ninalink.com/ft-myers-communities](http://www.ninalink.com/ft-myers-communities)(
   Heritage Palms gives the best example)
 * I know from my research this is not the perfect solution for cookies/wordpress.
   We are going to rebuild these properly, but this first one has to be out the 
   door fast, and I didn’t have my dev person to try to help me get it off the ground.
   I am willing to add in a function reference etc. but I am a designer, not a coder
   so would need hand holding! Therefore, I am hoping the answer is fairly simple
   and we can utilize this javascript cookie just to get launched.
 * Thanks in advance for any pointers or suggestions!

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

 *  [Andrew Bartel](https://wordpress.org/support/users/andrew-bartel/)
 * (@andrew-bartel)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/passing-javascript-cookie-values-troubleshooting-needed/#post-3539908)
 * Hi Ducky,
 * Couple things, you can check if a cookie is set in your browsers so that there
   is no ambiguity. For example in Firefox latest it’s Privacy > Remove Individual
   Cookies. You can even see the data being stored.
 * Second, I’m not sure of your experience with WordPress so forgive me if I’m skipping
   over stuff or it’s overly obvious, but including javascript in templating systems
   like WordPress is rarely as simple as just plugging it in between the <head> 
   tags. Although that might work, it’s an imperfect solution and sort of defeats
   the entire purpose of using something like WordPress.
 * So, quick primer. WordPress has a serious of what are called action hooks and
   filters. You can add things on to each action call. For example, there is an 
   action named wp_enqueue_scripts. Guess what it does? Exactly. You should hook
   your javascript includes onto this action call. As you get more familiar with
   WordPress, you can put conditionals in so that certain scripts are only included
   on pages where they are necessary. Example below:
 * Go ahead and upload the javascript to your theme root (we’ll call it my.js for
   the example). Then, in your functions.php add:
 *     ```
       add_action('wp_enqueue_scripts','enqueue_my_javascript');
       function enqueue_my_javascript() {
       wp_register_script('my.js','my.js');
       wp_enqueue_script('my.js');
       }
       ```
   
 * Note that this is for front end javascript inclusion only. There is a separate
   hook for administrative js.
 * Make sense? Happy to explain further.
 * Some useful links:
    [Getting started with WordPress](http://codex.wordpress.org/Getting_Started_with_WordPress)(
   First article I read!) [Actions/hooks list, explanation](http://codex.wordpress.org/Plugin_API/Action_Reference)
   [WordPress template heirarchy](http://codex.wordpress.org/Template_Hierarchy)
 *  Thread Starter [siteducky](https://wordpress.org/support/users/siteducky/)
 * (@siteducky)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/passing-javascript-cookie-values-troubleshooting-needed/#post-3539912)
 * First, thanks for the response! And I am going to take you up on that “explaining
   further” 🙂
 * When you say upload your javascript to the root (my.js) – which javascript? There’s
   where the cookie is set, there is where the cookie is supposed to display and
   then there is the existing .js file (which currently I am calling from just above
   the script because I haven’t been able to insert it in header.php without breaking
   the theme).
 *  Thread Starter [siteducky](https://wordpress.org/support/users/siteducky/)
 * (@siteducky)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/passing-javascript-cookie-values-troubleshooting-needed/#post-3539916)
 * Also – my understanding from the javascript person who reviewed the issue (he
   was using firebug) was that the cookie was setting. I reviewed cookie information
   in Firefox, per your suggestion, and when I go to that page it doesn’t show any
   cookies as being set. It also shows no errors unless I enable strict – then there
   are a bazillion, but none seem to relate to my particular js function.

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

The topic ‘Passing Javascript Cookie Values – Troubleshooting Needed’ is closed 
to new replies.

## Tags

 * [cookies](https://wordpress.org/support/topic-tag/cookies/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [siteducky](https://wordpress.org/support/users/siteducky/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/passing-javascript-cookie-values-troubleshooting-needed/#post-3539916)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
