For WordPress, whenever I run the script below, the function bloginfo('name')
echoes, but it doesn't echo
inside the <h1> </h1>
tags. Is the way of echoing bloginfo
incorrect, or does bloginfo
always break?:
<?php
if (con) {
echo "<h1>" . bloginfo('name') . "</h1>";
}
?>
The script below works, but it spawns empty <h1> </h1>
tags when the condition is false, which isn't necessary.
<h1>
<?php
if (con) {
echo bloginfo('name');
}
?>
</h1>
You don't need echo
to retrieve the bloginfo.
This always prints a result to the browser. If you need the values for use in PHP, use get_bloginfo().
Instead of using echo, you can do something like this:
<h1><?php bloginfo('name'); ?></h1>
Or, if you want to store the blog name in a variable, you can use get_bloginfo()
as suggested in the documentation:
<?php
$blog_title = get_bloginfo();
?>
<h1> <?php echo $blog_title; ?> </h1>
Hope this helps!