WordPress.org

Support

Support » Themes and Templates » Post title is being displayed instead of Page title

Post title is being displayed instead of Page title

  • I’ve created a simple function to display the page title. I’ve had to use some conditionals to try and change the title on the blog to use wp_title(); because get_the_title ends up displaying a post title instead of the page title. I’ve used this code but it doesn’t seem to work, I’m still getting a post title.

    function ls_page_title() {
    
    		$checkbox = get_post_meta( get_the_id(), 'ls_disable_page_title', true);
    		// $pageTitle = get_post_meta( get_the_id(), 'ls_page_title', true) ? get_post_meta( get_the_id(), 'ls_page_title', true) : get_the_title();
    
    		if ( is_page( get_option('page_for_posts') ) ) {
    			$pageTitle = wp_title('', false);
    		}
    		else {
    			$pageTitle = get_post_meta( get_the_id(), 'ls_page_title', true) ? get_post_meta( get_the_id(), 'ls_page_title', true) : get_the_title();
    		}
    
    		if ( $checkbox !== '1' ) {
    			echo '<h1 class="page-title">' . $pageTitle . '</h1>';
    		}
    
    	}
Viewing 1 replies (of 1 total)
  • Better yet, as you’ll notice I’ve added a part to let the user specify their own title should they not actually want the one used for the page. As I set my Blog page to ‘Blog’ I’d like the title to be Blog then but still allow the user to add a custom title should they want to.

Viewing 1 replies (of 1 total)
  • The topic ‘Post title is being displayed instead of Page title’ is closed to new replies.