Support » Fixing WordPress » Pass parameters to javascript using wp_localize_script

  • I have read a half-dozen examples of how to pass parameters to javascript and they all describe the process in a very similar manner but don’t speak to one event: how does the javascript code actually get called? I have seen several examples where the code is tested in $document.ready, but can’t get them to work.

    Here is my php code:

    $base_id = 'id_'.wp_create_nonce("postlister");
    $parms = array(
        'url'       => $url,
        'action'    => $action,
        'base_id'   => base_id );
    wp_localize_script(self::slug.'-postlister', 'postlister_parms', $parms);

    and m jQuery code:

    jQuery(document).ready(function ($) {
        if (postlister_parms !== undefined) {
            var parms = postlister_parms;
            $.diagnostic('postlister loaded');

    When the jQuery code executes, postlister_parms is undefined.

    Please help me spot what I am obviously missing.

  • The topic ‘Pass parameters to javascript using wp_localize_script’ is closed to new replies.