Proper Script for h1 tag

I have an issue with my website. this is not functioning with my given PHP script to take the Site Title as “H1” tag on the Home page(-home page.php). it seems empty in the source code view.
What is the right script to pull “Site Title” as “H1” tag in action?

Here is script

<?php : if( have_posts() ) while( have_posts() ) : the_post() ?>
            <h1><?php the_title() ?></h1>
            <?php the_content() ?>
        <?php endwhile; endif; ?> 

I have already tried removing if( have_posts() ) but it didn’t work.
And again added

<?php
  if(is_front_page()) { // check if we're on the homepage
    echo '<h1>my site Title</h1>'; //
  }
?>

removing the upper quoted script. But still, it is not working.

I am using “Frida” paid Theme, no child version.

What will be a better option to get rid of this issue?

So what this tells me is that the_title() returns the title, it doesnt echo it out for you. In which case
<?php the_title() ?>

is an empty statement.

<?php "John Smith" ?> doesnt tell PHP to DO anything, it just says “here is a string.”
There are two ways to fix it.
Explicit Echo:
<?php echo the_title(); ?>
Implicit Echo:
<?= the_title() ?>

How it works: <?= is a special PHP shorthand, called a short_tag, which is equivalent to “echo this”

thanks,
But these 2 corrections didn’t worked.
have a look at view-source:https://gadjetree.com/

There is no h1 tag on that page.

What’s the code for the_title() ? Are you sure it’s actually returning a value?

I was about to say the same.
To me that suggests that the conditions are not being met.

<?php : if( have_posts() ) while( have_posts() ) : the_post() ?>

or

if(is_front_page()) { // check if we're on the homepage

Where exactly on the page are you expecting to see the <h1>?

Oh, I see now that the thread has been re-tagged as Wordpress. That makes sense.

the_title() in a wordpress page can only be executed inside “The Loop”. If you’re trying to access it outside The Loop, you need get_the_title() instead. (See Reference: https://developer.wordpress.org/reference/functions/the_title/)

So either: You’ve removed the loop by removing the while, so the_title now returns nothing because you’re outside the Loop; the post has no title, or… uh… i’m struggling for a third option.

I want to see H1 tag the same as my Site’s title. It’s only for the home page. Other pages are functioning perfectly.
Only the Home page script is not working. I have given the site Name and Title in theme customization. But can’t see H1 tag on the “Source code” of the Home page, while other pages are showing H1 tag.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.