php - WordPress: using the_title() on posts page
Get the solution ↓↓↓I have a page called 'News' and have set this to be my posts page in my WP settings.
However, whenever I callthe_title
(outside of the loop) it gives me the title from the first blog post, not the page itself.
Is there a way around this?
I've tried usingwp_title('');
but then it gives me the page title + the site title... which isn't what I want either.
Answer
Solution:
You can usesingle_post_title()
for this. It will output the name of your posts page:
<?php single_post_title(); ?>
This will output the name. If you do not want to output but return it, you can set the second parameter of the function to false: https://developer.wordpress.org/reference/functions/single_post_title/
<?php $pagename = single_post_title( '', false ); ?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: regex stop at first match
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.