I've registered my custom post type in functions.php like so:

function whatwedo_custom_post_type()
                           'labels'      => array(
                               'name'          => __('What We Do'),
                               'singular_name' => __('What We Do'),

                           'public'      => true,
                           'has_archive' => true,
                           'supports' => array('title', 'editor', 'thumbnail'),
                           'capability_type' => 'post',
                           'capabilities' => array(
                           'create_posts' => 'do_not_allow',
                           'map_meta_cap' => true, 

add_action('init', 'whatwedo_custom_post_type');

Currently, I have the post title hardcoded within my frontpage.php template like so:

<h1 class="ft-center">WHAT WE DO</h1>

I need to display the post title dynamically instead, meaning - whenever I change the custom post title in admin, I want to display the changed title on front-end. Currently, when I try to display the custom post title (out of the loop) with

<?php echo get_the_title( ); ?>

it displays the page title, instead of post title. What should I do to display the custom post title instead?

  • 2
    When you call get_the_title() outside of the loop it defaults to the current page. Your best bet is to use WP_Query to get the post you wish to display on the frontpage.php (You can use the post ID to do this) and use get_the_title() inside of the loop. Here is a answer on how to use WP_Query how I have mentioned. wordpress.stackexchange.com/questions/20037/… May 21 '18 at 10:18
  • Glad I could help :) May 22 '18 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.