【问题标题】:Custom template page header not loading style.css in wordpress自定义模板页眉未在 wordpress 中加载 style.css
【发布时间】:2013-10-31 08:10:19
【问题描述】:

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

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

get_header();

//some code here

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

【问题讨论】:

    标签: php html wordpress


    【解决方案1】:

    请勿在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 中的关键概念,因此绝对值得!

    【讨论】:

      猜你喜欢
      • 2017-06-19
      • 2020-05-24
      • 2021-02-14
      • 2016-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-27
      相关资源
      最近更新 更多