WordPress.org

Ready to get started?Download WordPress

Forums

Using custom fields for title and meta tags (2 posts)

  1. Adam_C
    Member
    Posted 3 years ago #

    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 } ?>
  2. Adam_C
    Member
    Posted 3 years ago #

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

    That should be I can't!

Topic Closed

This topic has been closed to new replies.

About this Topic