使用带有wordpress入队的header()

时间:2012-06-21 18:01:14

标签: php javascript wordpress content-type

我基本上试图使我的js和css文件动态化。我已经尝试了几种不同的方法来做这件事,但它似乎并不适合我。任何帮助将不胜感激!

的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 (我已经尝试过fnp_jquery.js.php fnp_jquery.php和fnp_jquery.js)

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

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

$(document).ready(function() {
   //Javascript here
});

1 个答案:

答案 0 :(得分:1)

你的问题究竟是什么,你的脚本没有被剔除,它没有得到正确的服务?

Fireup firebug或您在浏览器中使用的任何控制台(通常是F12),如果标题真的推出了text / javascript并且内容真的存在,那么请查看网络选项卡。