Forums

Custom Fields for use in TITLE - For SEO (3 posts)

  1. anewidentity
    Member
    Posted 6 months ago #

    I am running across a problem where I would like to use data from my Custom Fields for use in my TITLE -

    ie:

    [theTitle()] at [custom_field_1_shop] in [custom_field_2_city], [custom_field_3_state]
    would read:

    HotDogs at Nathan's Hot Dogs in New York, NY

    Here is the code I am using to generate my title currently:

    <title>
    
    <?php if (is_home () ) {
    	bloginfo('name'); ?> | <?php bloginfo('description');
    } elseif ( is_category() ) {
        single_cat_title(); echo ' - ' ; bloginfo('name');
    } elseif (is_single() ) {
    
            single_post_title();
    		echo the_ID();
    		echo "at ";
    		echo $custom_field_1_shop;
    		echo " in ";
    		echo $custom_field_2_city;
    		echo ",";
    		echo $custom_field_3_state;
    
    } elseif (is_page() ) {
        bloginfo('name'); echo ': '; single_post_title();
    } else {
        wp_title('',true);
    } ?>
    </title>

    thanks for the help!
    much appreciate!

  2. iridiax
    Member
    Posted 6 months ago #

    <title> is not part of the Loop and the post meta (custom field) functions need to be in the Loop. This is why the easiest option is to just use a custom title plugin for this (the same thing goes for meta descriptions and meta keywords).

  3. anewidentity
    Member
    Posted 6 months ago #

    the only problem with those custom title plugins is that they still only let you access general objects like post title and post author. None of them (that I have found) let you tap into the posts actual meta data or custom fields.

Reply

You must log in to post.

About this Topic