wp_title() return value can't be styled [close

2019-08-20 04:08发布

问题:

The title is displayed before my image and is not styled. How to fix it?

$tytul = wp_title();
echo '<img class="icon" src="http://site.pl/site/icon.png" /><h2>'.$tytul.'</h2>';

回答1:

wp_title() will print the content itself, not return it, so echo wp_title() wont give you anything from the echo, but will print the title. If you use var_dump(wp_title()), you will see the title, then the result is NULL. What you want is:

echo '<img class="icon" src="http://site.pl/site/icon.png" /><h2>';
wp_title();
echo '</h2>';