Custom CSS on a page in Wordpress

Good morning,

I created a different background and several other images for certain pages of our site. Currently, the code below works well with the kids page on our site.

<body<?php if ( is_page(array('kids'))) {
echo ' class="kids" '; } ?>>

I am trying to figure out how to add the same CSS to other pages under the page for children. So, if you go to kids / block parties, how can I add it to the code to call this special CSS?

I tried below

<body<?php if ( is_page(array('kids, kids/block-party'))) {
echo ' class="kids" '; } ?>>

the comma does not appear to be registered for any reason.

This is a Wordpress download site.

thank

+3
source share
4 answers

Another option is to simply replace

<body>

with

<body <?php body_class(); ?>>

Then you can configure it via css as follows:

body.page-id-2, body.parent-pageid-2 { background-color: red; }

/ , . , .

+4

, ""

<body<?php if ( is_page(array('newsletter-1', 'newsletter-2', 'newsletter-3'))) { echo '   class="myclass" '; } ?>>
+3

, , .

script . , .

header.php:

<?php 
    //set page id 
            $page_id = '98';

           //get page children 
    $children = get_pages('child_of='.$page_id);
    foreach($children as $child){
       $children_ids = $child->ID;
    }

    if(is_page($page_id) || is_page($children_ids)){
       echo 'class="kids';
    }

? >

, , !

+1

: , 3 WP, . HTML CSS:/

Answer: You can use a template file assigned to any number of pages to add specific CSS / Javascript as follows:

<?php
function my_scripts_method() {
    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');
    wp_enqueue_script( 'jquery' );
}    

add_action('wp_enqueue_scripts', 'my_scripts_method');
?>

Source: http://codex.wordpress.org/Function_Reference/wp_enqueue_script

+1
source

Source: https://habr.com/ru/post/1760575/


All Articles