• Hi all,

    I’d like to automatically add a keyword or tag when I create a post.

    Each category will have a keyword/tag associated:

    When I create a post under CategoryA => KeywordA is automatically added
    When I create a post under CategoryB => KeywordB is automatically added
    When I create a post under CategoryC => KeywordC is automatically added

    Any idea on how I can achieve this?
    Many thanks in advance
    Sarah

Viewing 1 replies (of 1 total)
  • You could adding something like:

    <?php if (is_category()) echo '<meta name="keywords" content="' . strtolower(single_cat_title()) . '" />';?>

    to header.php. I tend to use a function that covers different post/archive.page types:

    FUNCTIONS.PHP

    function theme_meta_keywords() {
    	$my_output = '';
    	global $post;
    	switch(true) {
    		case (is_category()):
    		$my_output .= strtolower(single_cat_title());
    		break;
    
    		case (is_tag()):
    		$my_output .= strtolower(single_tag_title());
    		break;
    
    		case (is_archive()):
    		$my_output .= __('archives ', 'pastels') ;
    		if(is_year()) $my_output .= get_the_time('Y');
    		if(is_month()) $my_output .= strtolower(get_the_time('F Y'));
    		if(is_day()) $my_output .= strtolower(get_the_time('l F Y'));
    		break;
    
    		case (is_single() || is_page()):
    		$my_output .= strtolower(trim(wp_title('',false,'')));
    		if(get_post_meta($post->ID, 'keywords', true) !='') $my_output .= ' '.get_post_meta($post->ID, 'keywords', true);
    		$my_tags = get_tags(array('orderby' => 'count', 'order' => 'DESC'));
    		foreach ($my_tags as $my_tag) {
    			$my_output .= ' '.$my_tag->name;
    		}
    		break;
    
    		default:
    		$my_output .= wp_specialchars( strtolower( get_bloginfo('name').' '.get_bloginfo('description') ) );
    	}
    	return $my_output;
    }

    HEADER.PHP
    <meta name="keywords" content="<?php echo theme_meta_keywords();?>" />

Viewing 1 replies (of 1 total)
  • The topic ‘How to automatically add certain keywordor tag to post’ is closed to new replies.