自定义模板页眉不加载wordpress中的style.css

enr*_*qg9 2 html php wordpress

我在自定义模板页面上调用标题,get_header();但是加载标题而没有使用style.css破坏网站.我注意到如果我将标题放在某些代码的顶部,样式表加载就好了,例如:

<?php
/*
    Template Name: Sample Template
*/

get_header();

//some code here
Run Code Online (Sandbox Code Playgroud)

我需要在某些代码下面加载标题,因为我使用的是cookie,据我所知,应该在任何HTML之前生成cookie.

frn*_*nhr 5

不要在上面放置任何代码get_header().相反,使用动作"挂钩"并在那里做一些工作.

例如,您可以使用以下get_header操作:

// in functions.php :

add_action( 'get_header', 'set_my_cookies' );
function set_my_cookies() {
    // ... set those cookies
}
Run Code Online (Sandbox Code Playgroud)

请参阅http://codex.wordpress.org/Plugin_API/Action_Reference/get_header

更多关于行动:http://codex.wordpress.org/Plugin_API

一开始可能需要花一些时间来处理动作(和过滤器),但这些是WordPress中的关键概念,所以它绝对值得!