N
N
Nikita Ivanov2013-12-01 12:59:23
PHP
Nikita Ivanov, 2013-12-01 12:59:23

How to hook CSS in Wordpress using in_category() and is_page() functions?

How to hook css with these functions?
The essence is something like this:
if category/page 1,2,3
use css file A
if category/page 4,5,6
use css file B
otherwise use css file C

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LeeMiller, 2013-12-01
@rekurt

// Если в категории xxx и на странице yyy, Подгрузить xy.css
<?php if ( in_category('xxx') || is_page('yyy') ) { ?>
<link href='xy.css' rel='stylesheet' type='text/css'>
<?php } ?>

// Если ничего из вышеперечисленного, то подгрузить обычный css
<?php else { ?>
<link href='style.css' rel='stylesheet' type='text/css'>
<?php } ?>

To specify multiple rules, can be used as || , as well as arrays. note:
1. is_category('') || in_category('') || is_page('')
​​1. in_category( array( 'a', 'b', 'c')
Read more in the Wordpress codex

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question