Skip to content
Advertisement

How to set TWO first words of a slider header with a different color using variables in php?

There is a template https://wordpress.org/themes/bizberg/.

In “Customize” the slider title type is adjustable, and the title’s first word color could be replaced with a theme color. BUT there’s no sense to set a different color on an article “the” in sentence “The world is beautiful”. It should be at least first TWO words “The Future”, “The World” etc.

ANY IDEAS HOW TO MAKE IT WORK?

Thank you in advance!

(php code is below)

functions.php:

return '<h1 class="slider_title_layout_' . $slider_title_layout . ' ' . $slider_text_align . '">' .  '<span class="firstword">'.$title[0].'</span>'.substr(implode(" ", $title), strlen($title[0])) . '</h1>';

front-page-hero.php:

array(
            'element'  => '.slider_title_layout_3 .firstword,.slider_title_layout_4 .lastword',
            'property' => 'color'
        ),

Advertisement

Answer

Thanks to @CBroe‘s tip!

“Replace both occurrences of $title[0] with $title[0].’ ‘.$title[1].”

It worked wonderfully!

Also I’ve received a perfect answer from @Sergei Kirjanov.

So if you need to highlight a few title words only in certain slides, put the ” ^ ” sign after necessary words and change the php-code for :

$title = explode( strpos($title, "^") ? "^" : " ", $title );

It says, if a string has “^” then separate the colored title part after it, otherwise as usual after the space ” “.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement