ifnord
1/22/2017 - 1:50 PM

Autom. SEO Tags vergeben // Source: https://fastwp.de/2161/

Autom. SEO Tags vergeben // Source: https://fastwp.de/2161/

<?php echo FastWP_seo(); ?>
function FastWP_seo() {
	global $page, $paged, $post;
	$default_keywords = 'KEYWORDS EINFÜGEN';
	$output = '';

	$description = get_bloginfo('description', 'display');
	$pagedata = get_post($post->ID);
	if (is_singular()) {
	if (!empty($pagedata)) {
			$content = apply_filters('the_content', $pagedata->post_content);
			$content = substr(trim(strip_tags($content)), 0, 145) . '...';
			$content = preg_replace('#\n#', ' ', $content);
			$content = preg_replace('#\s{2,}#', ' ', $content);
		} 
	} else {
		$content = $description;	
	}
	$output .= '<meta name="description" content="' . esc_attr($content) . '" />' . "\n";

	$cats = get_the_category();
		if (!empty($cats)) foreach($cats as $cat) $keys .= $cat->name . ', ';
		$keys .= $default_keywords;
	$output .= "\t\t" . '<meta name="keywords" content="' . esc_attr($keys) . '" />' . "\n";

	if (is_category()) {
		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
		if ($paged > 1) {
			$output .=  "\t\t" . '<meta name="robots" content="noindex,follow" />' . "\n";
		} else {
			$output .=  "\t\t" . '<meta name="robots" content="index,follow" />' . "\n";
		}
	} else if (is_home() || is_singular()) {
		$output .=  "\t\t" . '<meta name="robots" content="index,follow" />' . "\n";
	} else {
		$output .= "\t\t" . '<meta name="robots" content="noindex,follow" />' . "\n";
	}

	$url = ltrim(esc_url($_SERVER['REQUEST_URI']), '/');
	$name = get_bloginfo('name', 'display');
	$title = trim(wp_title('', false));
	$cat = single_cat_title('', false);
	$search = get_search_query();

	if ($paged >= 2 || $page >= 2) $page_number = ' | ' . sprintf('Seite %s', max($paged, $page));
	else $page_number = '';

	if (is_home() || is_front_page()) $seo_title = $name . ' | ' . $description;
	elseif (is_singular())            $seo_title = $title . ' | ' . $name;
	elseif (is_category())            $seo_title = '' . $cat . ' | ' . $name;
	elseif (is_archive())             $seo_title = ' ' . $title . ' | ' . $name;
	elseif (is_search())              $seo_title = '' . $search . ' | ' . $name;
	elseif (is_404())                 $seo_title = '' . $url . ' | ' . $name;
	else                              $seo_title = $name . ' | ' . $description;

	$output .= "\t\t" . '' . "\n";

	return $output;
}