2

How can I have the site name with a span html tag without hard-coding it in a template? [ex. Good<span>4</span>You]

6
  • You want the site name so that you can use it in content? You say, "without hard-coding it in a template"; do you want to use it, for example, within your node body (From the admin interface)? Commented Jul 29, 2013 at 19:41
  • I've got the site name on the header and that's all. I just want to set a different color for just one word of my site name. Check the example of my question that I just edited. So if my website's site name was Good4You, I'd like to have a red colored "4" while the rest of the site name would be green.
    – Nim
    Commented Jul 29, 2013 at 19:46
  • You have to use JavaScript if you don't want to modify a template file. Can I ask why you don't want to modify it? Commented Jul 29, 2013 at 20:09
  • Maybe the best way is to use a template file after all. I was just curious if there is a "cleaner" way to achieve this throughout drupal interface after installing a module or smth. :) thanks alot @ChrisRockwell
    – Nim
    Commented Jul 29, 2013 at 20:22
  • 1
    I think the Drupal way would be to just modify html.tpl.php. Commented Jul 29, 2013 at 20:24

3 Answers 3

2

Its not at all difficult. I tried it in Drupal 7.22

Goto Configuration => Site Information => Site Name =>

My Site <span class="dummy-class">This is my new website</span>

Add whatever tags you like to have. But remember site title itself is already inside <span> tag, which means you have some restriction (Span tag is not container).

This is what it looks when I inspect it using firebug in mozilla. enter image description here

In your case, its Good<span>4</span>You. Just by using css you can do the magic.

1

My suggestion would be to add a block via admin/structure/block/add and create the exact markup you want.

Then add the block to the region you want (probably Header), style, disable site name and site slogan in your theme settings, and go on your way.

0

And here comes the template way :), place in template.php in your theme and change MYTHEME to the machine name of your theme.

function MYTHEME_preprocess_page(&$variables) {
  $variables['site_name'] = 'Good<span>4</span>You';
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.