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.
bloginfo() documentation
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!
bloginfo() prints the information without needing to echo it. bloginfo() actually seems to return nothing at all, hence why your echo bloginfo('name'); is not working as expected. You can find more information about how bloginfo() works here; Wordpress Function Reference
.
From the examples section, you can find the following example usage;
<h1><?php bloginfo('name'); ?></h1>
If you want to retrieve blog information as a string, you can use get_bloginfo() with the same options that bloginfo() supports. More information about get_bloginfo() can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With