WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Fields on Pages outside of loop? (3 posts)

  1. meko
    Member
    Posted 7 years ago #

    I would like to have two unique pieces of text -- a title and subtitle -- displayed at the top of each of my pages.

    I thought I could accomplish this using custom fields, but I am not sure if it is possible to get the values of custom fields outside of the loop?

    I tried the Get Custom Field Values plugin, but it displays the same text for each of the pages instead of pulling the custom field value for each page.

    Any suggestions?

  2. BPartch
    Member
    Posted 7 years ago #

    Hello

    You can go into page.php file and hardcode what you want in there above the loop and use some if/else conditions to switch out the text for various pages. :)

  3. meko
    Member
    Posted 7 years ago #

    Thanks. I did figure out a way to do just what I wanted using a combination of the SEO Title Tag plugin and if/else statements. I installed the plugin, and added the following to page.php:

    <div id="header">
    
    <h1><?php if(is_home()) {
    			echo 'Home Page Title';
    		}
    		else
    		{
    		the_title();
    		}
    ?>
    </h1>
    <h2><?php if (function_exists('seo_title_tag')) { seo_title_tag(); } else echo 'subtitle'; ?></h2>
    
    </div>

    It looks kind of like this on the site (plus some css formatting):
    Title Subtitle

    Not sure if this was the best way to implement this, but it works for me :)

Topic Closed

This topic has been closed to new replies.

About this Topic