WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Change the title of a Sticky post (5 posts)

  1. jonfoster
    Member
    Posted 3 years ago #

    Hi everyone,
    I'm quite new to the whole WordPress thing, and haven't had much experience with CSS either, so sorry if this is a bit obvious - or not written properly!
    Basically I'd like to know how I can make the title of Sticky posts show up differently to the title of normal posts - specifically be <h1> rather than <h2>.

    Thanks in advance,
    Jon

  2. Jackson
    Member
    Posted 3 years ago #

    You should look at using the 'is_sticky()' conditional in your theme.

    Rough example (not tested)

    if(is_sticky) {
      echo '<h1>'.get_the_title().'</h1>';
    } else {
      echo '<h2>'.get_the_title().'</h2>'
    }
  3. jonfoster
    Member
    Posted 3 years ago #

    Thats great - I'll give it a go.

    Thank you!

  4. Mark / t31os
    Moderator
    Posted 3 years ago #

    get_the_title() is not santized, use the_title() instead.

    <?php if( is_sticky() ) : ?>
    	<h1><?php the_title(); ?></h1>
    <?php else : ?>
    	<h2><?php the_title(); ?></h2>
    <?php endif; ?>
  5. jonfoster
    Member
    Posted 3 years ago #

    Mark - that's worked perfectly - thank you SO much.

    Jon

Topic Closed

This topic has been closed to new replies.

About this Topic