0

I am trying to acheive the following output in my HTML

<h1>This is the <span class="highlighted-text">Blog Title</span></h1>

Using my basic knowledge of the Wordpress Codex and PHP, I am currently achieving this using the following technique:

<?php

    $siteNameFull = get_bloginfo("name");
    $nameArray = explode(" ", $siteNameFull, 4);

?>

<h1><?php echo $nameArray[0] . " " . $nameArray[1] . " " . $nameArray[2] . "<span class='highlighted-text'>" . " " . $nameArray[3] . "</span>" ?></h1>

This outputs the HTML exactly as I want, but leaves me feeling a bit uneasy...

I suspect I am on the right track by using the explode function, but the ugly concatenation when I want to piece it all back together feels like a horrible way to do things.

Can someone point me in the right direction here please!

Many thanks

BuiltBySam
  • 11
  • 1
  • 4

1 Answers1

0

Try this:

<?php
    $siteNameFull = get_bloginfo("name");
    $nameArray = explode(" ", $siteNameFull, 4);
    $nameArray[3]= '<span class="highlighted-text">'.$nameArray[3].'</span>';
    $title_name= implode(" ", $nameArray);
?>
<h1><?php echo $title_name; ?></h1>
sariDon
  • 7,782
  • 2
  • 16
  • 27