每个wordpress帖子/页面触发一次钩子?

每个wordpress帖子/页面触发一次钩子?,wordpress,Wordpress,在我正在编写的插件中,我希望为页面上的每个页面/帖子将特定于页面/帖子的css文件(在html标题中)排队 例如:如果页面加载帖子44和56,我需要: <link rel='stylesheet' id='post-44-css' href='http://test/wp-content/custom/post-44.css?ver=4.0.1' type='text/css' media='all' /> <link rel='stylesheet' id='post-56

在我正在编写的插件中,我希望为页面上的每个页面/帖子将特定于页面/帖子的css文件(在html
标题中)排队

例如:如果页面加载帖子44和56,我需要:

<link rel='stylesheet' id='post-44-css'  href='http://test/wp-content/custom/post-44.css?ver=4.0.1' type='text/css' media='all' />
<link rel='stylesheet' id='post-56-css'  href='http://test/wp-content/custom/post-56.css?ver=4.0.1' type='text/css' media='all' />
更新的答案与返工功能

我使用了
wp\u enqueue\u脚本
action,并为单个帖子/页面提供了一个条件。有关更多信息,请查看相应的法典页面。 和

现在,您的代码可能如下所示:

add_action('wp_enqueue_scripts', 'function_enqueuing_css');
function function_enqueuing_css() {
    global $wp_query;
    $id = $wp_query->post->ID;

    if(is_single()) {
        wp_enqueue_style( 'post-'.$id, 'path-to-file-'.$id.'.css', array(), '', 'all');
    }
}

同样的方法也可以用于js文件。

您能修复代码吗?棘手的部分被留白了(即:我如何获得每个帖子的id?@SergeProfaFileeCook改进并测试了代码,现在应该可以正常工作了。
add_action('wp_enqueue_scripts', 'function_enqueuing_css');
function function_enqueuing_css() {
    global $wp_query;
    $id = $wp_query->post->ID;

    if(is_single()) {
        wp_enqueue_style( 'post-'.$id, 'path-to-file-'.$id.'.css', array(), '', 'all');
    }
}