Inserting Title_Field into WordPress Pages and Posts

Have you ever wanted to insert the title of a page or post into a template or into the page or post content? (Or any other WordPress fields.)

You do not have to know PHP to add PHP code to your WordPress pages and posts. You will need to figure out the syntax you need to add, but with a quick search on Google (or your favorite search engine), you can usually find the code you need.  In this example, I’m using “the_title” field to display the title of the page you are on. Here are a couple of solutions that I found easy using plugins.

Inserting the title of the page or post into Widget Section.

I used this to design a Hero Section Template for our website. Adding the title of each page dynamically to a template can easily be done using a widget and PHP Code Widget Plugin.

  1. Install PHP Code Widget Plugin
  2. Add the following code to the text widget (the heading tags are optional):
    <h1><?php the_title(); ?></h1>

The Text widget allows you to insert Text and/or HTML code, but the PHP Code Widget plugin also parses any PHP code in the text widget and executes it. All PHP code must be enclosed in the standard php opening and closing tags ( <?php and ?> ) for it to be recognized and executed.

Inserting the title into page or post content.

If you want to insert PHP code directly into your content, you might try the Insert PHP Plugin. This plugin allows you to insert the php into the page or post content using insert_php tags instead of <?php..?>. For example, I’ll insert the title of this page using the insert php tag format required by this plugin: Inserting Title_Field into WordPress Pages and Posts.  Go to the plugin page to read the instructions.

I found both of these methods easy and they just worked.

 


ZPat Web Design. Copyright © 2017. All Rights Reserved.

 

 

Leave a reply