title: How can I get the current page name in WordPress?
body: <p>What PHP code can be used to retrieve the current page name in a WordPress theme?</p>
  <p>All the solutions I have seen so far:</p>
  <ul>
  <li><code>the_title()</code></li>
  <li><code>get_page()-&gt;post_name</code></li>
  <li><code>get_post()</code></li>
  <li>etc.</li>
  </ul>
  <p>But these don't work for a page that contains post entries. They will all return the name of the latest blog entry.</p>
  <p>Stated another way, assume that you have a page created in WordPress with the name &quot;My News&quot;. This page is set as the &quot;post page&quot;. Add a couple of posts to the page.
  Now, what API can be used to retrieve the string &quot;my-news&quot; instead of the name of the latest post?</p>
  <hr/>
  <p>I've found the following variable which seems to work.</p>
  <pre><code>$wp_query-&gt;queried_object-&gt;post_name
  </code></pre>
  <p>This is actually the URL friendly version of the page name (slug), which is what I was looking for too. This was tested with the default template (<a href="https://wordpress.org/themes/twentyten/" rel="noreferrer">Twenty Ten</a>). I'm really not sure why the two variables given below do not work on my site. Thanks to <a href="https://stackoverflow.com/questions/4837006/how-can-i-get-the-current-page-name-in-wordpress/4837579#4837579"><em>keatch</em> for the <code>print_r()</code> tip</a>.</p>
  <p>Now, why is this information hidden so deep down?</p>