I am trying to find out if you can enqueue a script in WordPress that has php variables within it. If this is possible how would it be done?

I have tried this, however I get errors.

function my_scripts_method() {
wp_enqueue_script(
    'custom-script',
    get_stylesheet_directory_uri() . '/masonry.php',
    array( 'jquery' )
);
}

add_action( 'wp_enqueue_scripts', 'my_scripts_method' );

Read more here: Enqueue WP Script that contained PHP variables


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: