Support » Plugins and Hacks » Using custom fields for title and meta tags

  • Yes, I know you can do this with plug-ins 🙂

    But I’m keen to use custom fields, however I can get the code to work.

    Specifically, I want to customise title tags for posts, and then apply same methodology to meta descriptions.

    I’ve tried the following – both with the latest WP version.

    <title>
    
    <?php if (is_home () ) {
        bloginfo('name');
    } elseif ( is_category() ) {
        single_cat_title(); echo ' - ' ; bloginfo('name');
    } elseif (is_single() ) {
        $customField = get_post_custom_values("title");
        if (isset($customField[0])) {
            echo $customField[0];
        } else {
            single_post_title();
        }
    } elseif (is_page() ) {
        bloginfo('name'); echo ': '; single_post_title();
    } else {
        wp_title('',true);
    } ?>
    </title>

    and

    <title><?php
    $titletag = get_post_custom_values("tag-title");
    if ( is_array($archivetitle) ) { ?>
    <?php echo get_post_meta($post->ID, "tag-title", true); ?>
    <?php }	else { ?>
    <?php the_title(); ?>
    <?php } ?>
Viewing 1 replies (of 1 total)
  • But I’m keen to use custom fields, however I can get the code to work.

    That should be I can’t!

Viewing 1 replies (of 1 total)
  • The topic ‘Using custom fields for title and meta tags’ is closed to new replies.