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]

  • 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)? – Chris Rockwell Jul 29 '13 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 Jul 29 '13 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? – Chris Rockwell Jul 29 '13 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 Jul 29 '13 at 20:22
  • 1
    I think the Drupal way would be to just modify html.tpl.php. – Chris Rockwell Jul 29 '13 at 20:24
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';
}

protected by Community Mar 13 at 4:09

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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