How can I get the current page name in WordPress?

Our QuestionsCategory: General QuestionsHow can I get the current page name in WordPress?
Ava asked 2 years ago

What PHP code can be used to retrieve the current page name in a WordPress theme?

All the solutions I have seen so far:

the_title()

get_page()->post_name

get_post()

etc.

But these don't work for a page that contains post entries. They will all return the name of the latest blog entry.

Stated another way, assume that you have a page created in WordPress with the name "My News". This page is set as the "post page". Add a couple of posts to the page. Now, what API can be used to retrieve the string "my-news" instead of the name of the latest post?

emotester Mod replied 1 year ago

Very poor demo of the features

emotester Mod replied 1 year ago

Wahts

emotester Mod replied 5 months ago

Demo text