0

I am trying to get the page title to show up inside various h1, h2 and p tags that i have part of the page template - so that when the template is applied to a page it will make the current page's page title appear wherever I add a shortcode or whatever is needed to pull the page title. When I add the following i am getting a blank...

Here's what I mean: I want "Find the best " to basically pull the page title so that if the title is video games it will display as "Find the best video games"

<h1 class="btx-heading-text btx-secondary-font btx-s-text-color btx-s- 
text-border" style="padding-right:25%; padding-bottom:5%; letter- 
spacing:-2px;"><span style="color: rgb(0, 0, 0);">Find the best&nbsp; 
</span><span style="color: rgb(126, 131, 142);"><?php get_the_title() ? 
></span></h1>

Currently, I only get the following "Find the best"

2 Answers 2

2

get_the_title() does not output anything - it's meant for being saved to a variable. Use just the_title(); in its place - that way it will be output. :)

3
  • When i add the <?php the_title(); ?> in a page itself it comes out blank. However when i added the <?php the_title(); ?> to a page template file it worked so if i wanted to add <?php the_title(); ?> to a single page itself how would i do so? Also to provide more context i want to add the <?php the_title(); ?> inside a shortcode in order to have the shortcode replace part of it with the specific page's title, how would i do that? For Example: the shortcode [products columns="3" attribute="season" terms="warm" orderby="date"] Except replace the seasons with the page title... thanks!
    – sn22
    Commented Sep 17, 2018 at 20:46
  • Right, you can't add PHP directly into the editor. If you want to add it manually every time rather than embedding it into a template, that's deserving of a separate question.
    – WebElaine
    Commented Sep 17, 2018 at 21:13
  • wordpress.stackexchange.com/questions/314457/… I have created a new question - hope you are able to help, thanks again in advance!
    – sn22
    Commented Sep 17, 2018 at 21:40
0

You could also use ...

<?php echo get_the_title() ? 
></span></h1>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.