Custom CSS file per page template (8 posts)

  1. Mohidul Islam
    Posted 3 years ago #

    Hello everybody,
    Help me please. I am using twentyten theme. I wanted to create some custom page like About Us, Login, Register etc.
    Page template has been created. But problem is the css file. When I created a div id or class. And write some styles. There have no changes.
    Now how can I write stylesheet for my custom page template.
    What Can I Do Now ?
    Mohidul Islam

  2. serpico
    Posted 3 years ago #

    I would suggest adding the custom styles to the usual style.css file. You can apply your CSS code to specific pages by selecting elements using the body class. Details of this can be found within the codex here:

  3. Mohidul Islam
    Posted 3 years ago #

    Thanks for you reply serpico .
    I am try to add styles in style.css. But doesn't work. What can I do for work in style.css file.

  4. Mohidul Islam
    Posted 3 years ago #

    My custom page is about.php

  5. serpico
    Posted 3 years ago #

    Can you provide a link to your custom about page?

  6. Mohidul Islam
    Posted 3 years ago #

    Oh reasy sorry serpico,
    That is my localhost.

  7. serpico
    Posted 3 years ago #

    Take a look at the source code, you will see the body tag has a number of classes. One of these will be a specific page id.

    For example, you can then use the CSS:

    body.page-id-4 #wrapper { background-color:#000 !important }

    This will select the tag with an ID wrapper within the Page ID 4.

  8. Arie Putranto
    Posted 3 years ago #

    Or you can add another stylesheet to your theme directory and load it using conditional tags.

    For example:

    On your function.php

    // Replace # with the ID of your custom page

    if ( is_page( # ) ) {
    wp_enqueue_style( 'path/to/your/custom/css/file' );
    else wp_enqueue_style( 'path/to/your/original/css/file' );

    But if you only add minor change to the style, @serpico way would be proper.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.