• Resolved martinomagnifico

    (@martinomagnifico)


    I’m trying to get the titles of my pages in different colors. There are just a few pages that need recoloring, the rest can be the standard css assigned color. And I don’t want the title “Home” appearing on the home page.

    I think I understand that I need to start with that last bit, so the first “if” is about the homepage.

    This code here has the styling and the php combined. (I copied some bits form pieces I found) But it doesn’t work, I get a php parsing error.

    <?php if (!is_front_page()) { ?>
            <div class="post-headline"> 
    
            <?php
            if(is_page('newsletter')) { ?>
             <h2> <font color="blue"><?php the_title(); ?> </font> </h2>
             <?php } ?><?php
             elseif(is_page('advertising')) { ?>
             <h2> <font color="yellow"><?php the_title(); ?> </font> </h2>
            <?php } ?><?php
              else  { ?>
             <h2><?php the_title(); ?></h2>
             <?php } ?>
    
            </div>
    <?php } ?>

    Should I split the php and the css styling? Then the line would be something like

    <titlecolor><?php the_title(); ?></titlecolor>

    And it would put the if/thens in the css block. That would make it a dynamic css. And I wouldn’t know how to do that.

    Does anyone know how to fix my code? I really don’t know much about php, so I would be glad If you could help me.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Have you looked at the inbuilt body_class() template tag? It will add a whole range of classes automatically that you may be able to then use via CSS to style specific page titles.

    http://quirm.net/2009/08/07/changing-headers-with-wordpress-body_class/

    has a list of all of the available classes. For pages, you could try simply styling on slug-[pagename] – eg:

    .slug-newsletter .post-headline h2 {color:blue;}
    .slug-advertising .post-headline h2 {color:blue;}

    etc.

    Thread Starter martinomagnifico

    (@martinomagnifico)

    This worked, though not with slug…. I looked at your link, and tried it with page-id. That worked!!!! Thanks!!!!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Dynamic page title color css/php’ is closed to new replies.