WordPress.org

Support

Support » How-To and Troubleshooting » after breaking tagline into 2 lines, apply different style to each line

after breaking tagline into 2 lines, apply different style to each line

  • I have successfully split the tagline into 2 lines at a chosen character,with help from http://wordpress.org/support/topic/how-to-enter-a-new-line-in-tagline

    <h2 class="site-description"><?php echo str_replace('-','<br />',get_bloginfo('description')); ?></h2>
    and for the site title
    <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php echo str_replace('-','<br />',get_bloginfo('name')); ?></a></h1>
    Is it possible to style each line differently?
    Possibly by adding a span tag to each line within the h tags?
    I am working with twenty twelve on localhost (WAMP), so can’t post a link at the moment
    Thanks
    Mark

Viewing 4 replies - 1 through 4 (of 4 total)
  • How about doing something like this:

    <?php
      $site-description = explode('-', get_bloginfo('description'));
      $site-title = explode('-', get_bloginfo('name'));
    ?>

    Which creates an array for the site description and title split before and after the hyphen, respectively. Then you can put each portion of the array in span tags with classes you can style as you like:

    <h2 class="site-description"><?php echo '<span class="site-description">' . $site-description[0] . '</span><br /><span class="site-description-line2">' . $site-description[1] . '</span>'; ?></h2>

    and for the title:

    <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php echo '<span class="site-title">' . $site-title[0] . '</span><br /><span class="site-title-line2">' . $site-title[1] . '</span>'; ?></a></h1>

    thank you
    unfortunately this throws an error
    Parse error: syntax error, unexpected ‘=’

    Well, I don’t see any errors in the code right off, but I think I made PHP choke by using the hyphens in the variable names.

    Try this instead:

    <?php
      $sitedescription = explode('-', get_bloginfo('description'));
      $sitetitle = explode('-', get_bloginfo('name'));
    ?>
    <h2 class="site-description"><?php echo '<span class="site-description">' . $sitedescription[0] . '</span><br /><span class="site-description-line2">' . $sitedescription[1] . '</span>'; ?></h2>
    <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php echo '<span class="site-title">' . $sitetitle[0] . '</span><br /><span class="site-title-line2">' . $sitetitle[1] . '</span>'; ?></a></h1>

    If it still errors out, see if the line number the error prints out will narrow down the source of the error.

    thank you, that works.
    much appreciated

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘after breaking tagline into 2 lines, apply different style to each line’ is closed to new replies.
Skip to toolbar