admin管理员组文章数量:1433520
I would like to add dynamic classes from templates to tags like <main>
, <header>
, <footer>
which are defined in header.php and footer.php. This is something I would like to acheive:
header.php
<!doctype html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="profile" href="" />
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<header class="<?php dynamic_header_class(); ?>">
.
.
.
.
</header>
<main class="<?php dynamic_main_class(); ?>">
<div id="content" class="site-content">
about-template.php
<?php
/*
Template Name: About Page
*/
// Add header-interior class to <header>
set_header_class('header-interior');
// Add main-map-container class to <main>
set_main_class('main-map-container');
?>
contact-template.php
<?php
/*
Template Name: Contact Page
*/
// Add header-exterior class to <header>
set_header_class('header-exterior');
// Add main-no-footer class to <main>
set_main_class('main-no-footer');
?>
Wordpress do have body_class()
and post_class()
but they are limited to <body>
tag and corresponding <div>
respectively. Coming from twig which has a very easy way to do these things using {% set %}
tag. Can something reusable function or filter be created in wordpress where I could add different classes from different templates to tags like <main>
, <header>
etc.
本文标签: functionsHow to add class dynamically from templates
版权声明:本文标题:functions - How to add class dynamically from templates 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745594937a2665419.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论