I'm calling the permalink of post on submitting a form like below:

       var $this = $(this),
            category = $this.attr('data-event-category'),
            action = $this.attr('data-event-action'),
            label = $this.attr('data-event-label')
             permalink =  call_url["permalink"]

        self.track(category, action, permalink);

                console.log('tracking pushed: '+category+', '+action+', '+permalink+','+label)


Which I'm calling via my functions.php

    wp_register_script( 'analytics', get_template_directory_uri() . '/js/analytics.js','','1.0.1');
wp_enqueue_script( 'analytics' );
, "call_url"
, [
        "permalink" => get_permalink($post),


All works great and appear in my console fine.

Only thing is, I would like it to the permalink to appear as an data-attribute like the category, action and label.

For that I tried the below:

                 permalink =  $this.attr('call_url["permalink"]')

Which doesn't seems t work.

Any help will be super ??

Thank you !


To set an attribute you will need to do

 $(this).attr('data-url', call_url["permalink"]);

To update

$(this).data('url', call_url["permalink"]);
| improve this answer | |
  • Hi Jim, Thanks, May I know what is the 'url' referencing to ? Thanks – thibaultlgd Oct 30 '17 at 11:08
  • in the console it bring only the value [object Object] instead of the URl with this . .. – thibaultlgd Oct 30 '17 at 11:13
  • I think you need to filter down through the [object,Object] var obj = call_url["permalink"] console.log(obj[0].['permalink']) – Jim-miraidev Oct 30 '17 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.