1

I'm basically trying to make my js and css files dynamic. I've tried a few different ways of doing this and it isn't seeming to work for me. Any help would be greatly appreciated!

functions.php

function fnp_add_js() {
    //I've tried fnp_jquery.js.php fnp_jquery.php and fnp_jquery.js
    wp_register_script( 'fnp_jquery', plugins_url( 'fnp_jquery.js.php', __FILE__ ));

    wp_enqueue_script('fnp_jquery');
}

base.php

add_action('wp_enqueue_scripts', 'fnp_add_js');

jquery.js (I've tried fnp_jquery.js.php fnp_jquery.php and fnp_jquery.js)

<?php 
header('Content-type: text/javascript');

//I've also tried surrounding $(document).ready(function() {}  with echo ''; 
?>

$(document).ready(function() {
   //Javascript here
});
11
  • What is your problem exactly, your script doesn't get enqued, it doesn't get served correctly? Commented Jun 21, 2012 at 18:03
  • I believe it is getting enqueued, as the source shows the <script..></script> tag, however I dont think that it is reading the javascript correctly. Commented Jun 21, 2012 at 18:18
  • It was working fine before I tried to make the jquery.js file into a php file so that I could use php variables in the javascript Commented Jun 21, 2012 at 18:20
  • Ok, fireup firebug or whatever console you are working with in your browser (usually F12) and look in the network tab if the header is really pushing out text/javascript and if the content is really there Commented Jun 21, 2012 at 18:23
  • I couldn't find what you were talking about it firebug, however when I got to the script panel, it does not show the file loaded whereas other javascript files are. Commented Jun 21, 2012 at 18:29

1 Answer 1

1

What is your problem exactly, your script doesn't get enqued, it doesn't get served correctly?

Fireup firebug or whatever console you are working with in your browser (usually F12) and look in the network tab if the header is really pushing out text/javascript and if the content is really there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.