繁体   English   中英

自定义模板页面标题未在Wordpress中加载style.css

[英]Custom template page header not loading style.css in wordpress

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

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

get_header();

//some code here

由于我使用的是Cookie,因此我需要在一些代码下方加载标头,据我所知,应在任何HTML之前生成Cookie。

不要在get_header()上方放置任何代码。 取而代之的是,使用动作来“挂钩”并在那里做一些工作。

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

// in functions.php :

add_action( 'get_header', 'set_my_cookies' );
function set_my_cookies() {
    // ... set those cookies
}

参见http://codex.wordpress.org/Plugin_API/Action_Reference/get_header

有关操作的更多信息: http : //codex.wordpress.org/Plugin_API

首先,可能需要花一点时间来了解操作(和过滤器),但是这些是WordPress中的关键概念,因此绝对值得!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM