WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] how to bold part of the post title (9 posts)

  1. sundas
    Member
    Posted 12 months ago #

    hi, i have posts in the pinboard theme which when marked sticky becomes the slideshow on the main page and the post title becomes the slide title

    Is there any way i can make part of that title bold to differentiate between the words the come after the colon in the title e.g make

    "Spirit of the Awakened Warrior: The Keys to Accelerate Your Growth and Blessings"

    this, that is the part before the colon bolded

    "Spirit of the Awakened Warrior: The Keys to Accelerate Your Growth and Blessings"

  2. keesiemeijer
    moderator
    Posted 12 months ago #

    Try creating a child theme first. Copy slider.php to your child theme and change this:

    <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>

    to this:

    <?php
    $title = get_the_title( $post->ID );
    $new_title = '';
    // get title before ":";
    $before = substr( $title, 0, strpos( $title, ':' ) );
    if ( $before ) {
    	$new_title .= '<strong>' . $before . '</strong>' . stristr( $title, ':' );
    }
    $title = ( '' != $new_title ) ? $new_title : $title;
    ?>
    <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php echo $title; ?></a></h2>
  3. sundas
    Member
    Posted 12 months ago #

    it doesnt help, doing what you said makes the whole of the slider title bold and worse messes with the drop down menu, instead of dropping down all menu items become a part of the menu tabs and the top alignment gets messed up as well..

    see link below for better understanding

  4. sundas
    Member
    Posted 12 months ago #

  5. sundas
    Member
    Posted 12 months ago #

    and it also undoes the changes like background image

  6. alchymyth
    The Sweeper & Moderator
    Posted 12 months ago #

    totally alternative approach:

    add this filter to functions.php of your theme or child theme:

    add_filter( 'the_title', 'bold_before_colon' );
    function bold_before_colon( $title ) {
    if( is_sticky() && strpos( $title, ':' ) ) $title = '<span>'.preg_replace('#(:)#',':</span>',$title,1);
    return $title;
    }

    add this line to style.css of your theme or child theme:

    #slider .entry-title span { font-weight: bold; }
  7. sundas
    Member
    Posted 12 months ago #

    didnt work, I added the filter to functions.php on the first line and added the css code but the whole title becomes bold instead of just the part before colon :(

  8. alchymyth
    The Sweeper & Moderator
    Posted 11 months ago #

    I see it working in the web page you have linked earlier; IE8 and FF20

    try to clear the browser cache, with 'CTRL F5' or (several) 'reload'

  9. sundas
    Member
    Posted 11 months ago #

    omg! thankyou sooo very much Mr. alchymyth! it is working, thanks alot i could not have figured it out myself! really thanks a bunch

Reply

You must log in to post.

About this Topic