簡體   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