I'm very new to the world of php coding and have been learning basic php including 'if'/ 'else' rules but I've hit a brick wall and no amount of Googling has helped.
I am currently working on a WordPress theme template where the header is pulled dynamically:
<header class="page-title theme-bg-light text-center gradient py-5">
<h1 class="heading">
<?php the_title()
?>
</h1>
</header>
But as the blog page is set to be the posts page it shows the most recent post as the header title instead of 'Blog'. I've been tearing my hair out over the last two days trying to do if/then rules for instance:
<?php if (is_nav_menu_item($menu_item_id = 55)){
echo 'Blog';}
else get_the_title(the_title());
?>
To no avail. All I want is for blog page to be hard-coded as 'Blog' else retrieve the page titles as normal. Sometimes it remains unchanged, or it'll change all the page headers to 'Blog'.
A lot of other code I've seen is completely different to mine and I've tried some other things I read on WordPress' codex but I'm not really sure what I'm doing.
Thanks for your time!
the_title
always refers to the title of the current post, so if you are using a page named Blog to show your list of posts, it'll show Blog, but on individual posts it'll show their individual titles. If you want it to always be "Blog" there's a trivial solution, replace<?php the_title() ?>
withBlog
, literally select it in the editor, press delete and type the word Blog