get page name wp

To get the page name in WordPress, you can use the following steps:

  1. Identify the current post or page ID using get_the_ID() function.
  2. Use the get_post() function to retrieve the post or page object based on the ID obtained in the previous step.
  3. Access the 'post_title' property of the post or page object to retrieve the name or title of the page.

Here's an example code snippet that demonstrates how to get the page name in WordPress:

<?php
// Get the current post or page ID
$post_id = get_the_ID();

// Retrieve the post or page object based on the ID
$post = get_post($post_id);

// Get the title or name of the page
$page_name = $post->post_title;

// Output or use the retrieved page name
echo 'Page Name: ' . $page_name;
?>

Replace the echo 'Page Name: ' . $page_name; line with your preferred method of displaying or using the retrieved page name.