WordPress Meta Tag Generator

Generate a wp_head PHP snippet for meta descriptions, robots directives, theme-color, verification codes and Open Graph — no SEO plugin needed.

Runs in your browser

Settings

Yoast SEO, Rank Math, SEOPress or All in One SEO — avoids duplicate tags.

Meta description

63 characters — aim for 120–160.

Robots (via the wp_robots filter)

max-snippet:-1, max-image-preview:large, max-video-preview:-1

noindex, follow on:

Theme color & author
Author meta
Site verification

Paste the code or the whole <meta> tag — the token is extracted.

Social

og:title, og:url, og:type, og:description, og:image

Used when a post has no featured image. 1200×630 px works best.

functions.php snippet

/**
 * Custom meta tags for the document <head>.
 * Generated with Utilo — add to your theme's functions.php or a plugin.
 */

if ( ! function_exists( 'mytheme_seo_plugin_active' ) ) {
	/**
	 * Whether a full SEO plugin is handling meta tags already.
	 *
	 * @return bool
	 */
	function mytheme_seo_plugin_active() {
		return defined( 'WPSEO_VERSION' ) // Yoast SEO.
			|| defined( 'RANK_MATH_VERSION' ) // Rank Math.
			|| defined( 'SEOPRESS_VERSION' ) // SEOPress.
			|| defined( 'AIOSEO_VERSION' ); // All in One SEO.
	}
}

if ( ! function_exists( 'mytheme_meta_tags' ) ) {
	/**
	 * Prints meta tags early in wp_head.
	 */
	function mytheme_meta_tags() {
		if ( mytheme_seo_plugin_active() ) {
			return;
		}

		$description = '';
		if ( is_singular() ) {
			$post        = get_queried_object();
			$description = has_excerpt( $post )
				? $post->post_excerpt
				: wp_trim_words( strip_shortcodes( excerpt_remove_blocks( $post->post_content ) ), 30, '' );
		} elseif ( is_category() || is_tag() || is_tax() ) {
			$description = term_description();
		}
		if ( '' === trim( wp_strip_all_tags( $description ) ) ) {
			$description = __( 'Practical guides and tools for building faster WordPress sites.', 'mytheme' );
		}
		$description = wp_html_excerpt( trim( preg_replace( '/\s+/', ' ', wp_strip_all_tags( $description ) ) ), 160, '…' );

		if ( '' !== $description ) {
			printf( '<meta name="description" content="%s" />' . "\n", esc_attr( $description ) );
		}

		if ( is_singular( 'post' ) ) {
			$author = get_the_author_meta( 'display_name', (int) get_queried_object()->post_author );
			if ( $author ) {
				printf( '<meta name="author" content="%s" />' . "\n", esc_attr( $author ) );
			}
		}

		echo '<meta name="theme-color" content="#4f46e5" />' . "\n";

		// Open Graph.
		$og = array(
			'og:site_name' => get_bloginfo( 'name' ),
			'og:locale'    => get_locale(),
			'og:type'      => is_singular( 'post' ) ? 'article' : 'website',
			'og:title'     => wp_get_document_title(),
			'og:url'       => is_singular() ? wp_get_canonical_url() : home_url( user_trailingslashit( $GLOBALS['wp']->request ) ),
		);
		if ( '' !== $description ) {
			$og['og:description'] = $description;
		}
		$og_image = '';
		if ( is_singular() && has_post_thumbnail() ) {
			$og_image = get_the_post_thumbnail_url( get_queried_object_id(), 'large' );
		}
		if ( $og_image ) {
			$og['og:image'] = $og_image;
		}
		foreach ( $og as $property => $value ) {
			if ( $value ) {
				printf( '<meta property="%s" content="%s" />' . "\n", esc_attr( $property ), 'og:url' === $property || 'og:image' === $property ? esc_url( $value ) : esc_attr( $value ) );
			}
		}
		printf( '<meta name="twitter:card" content="%s" />' . "\n", esc_attr( $og_image ? 'summary_large_image' : 'summary' ) );
	}
}
add_action( 'wp_head', 'mytheme_meta_tags', 1 );

if ( ! function_exists( 'mytheme_robots' ) ) {
	/**
	 * Adjusts the core robots meta tag (WordPress 5.7+) instead of printing a second one.
	 *
	 * @param array $robots Associative array of robots directives.
	 * @return array
	 */
	function mytheme_robots( $robots ) {
		if ( mytheme_seo_plugin_active() ) {
			return $robots;
		}

		if ( is_date() || is_attachment() ) {
			$robots['noindex'] = true;
			$robots['follow']  = true;
		}

		if ( empty( $robots['noindex'] ) ) {
			$robots['max-snippet']       = '-1';
			$robots['max-image-preview'] = 'large';
			$robots['max-video-preview'] = '-1';
		}

		return $robots;
	}
}
add_filter( 'wp_robots', 'mytheme_robots' );

HTML output preview

Preview context
<meta name='robots' content='max-image-preview:large, max-snippet:-1, max-video-preview:-1' />
<meta name="description" content="Practical guides and tools for building faster WordPress sites." />
<meta name="theme-color" content="#4f46e5" />
<meta property="og:site_name" content="My Site" />
<meta property="og:locale" content="en_US" />
<meta property="og:type" content="website" />
<meta property="og:title" content="My Site – Tagline" />
<meta property="og:url" content="https://example.com/" />
<meta property="og:description" content="Practical guides and tools for building faster WordPress sites." />
<meta name="twitter:card" content="summary" />

Sample values stand in for your post data. The robots line is printed by WordPress core and adjusted by the filter.

Adding meta tags to WordPress without an SEO plugin

Not every site needs a full SEO plugin. Brochure sites, headless front ends, custom themes for clients and performance-focused builds often only need a handful of tags: a meta description, sensible robots directives, a theme-color, search-console verification codes and basic Open Graph data for link previews. This generator writes that as a small, reviewed PHP snippet hooked to wp_head.

Unlike the generic Meta Tag Generator, which produces static HTML for a single page, this tool generates dynamic WordPress code. The description comes from each post’s excerpt (or its first 30 words), taxonomy archives use the term description, and Open Graph images use the featured image — all escaped with esc_attr() and esc_url().

Robots directives are handled the modern way. Since WordPress 5.7 core prints its own robots meta tag through wp_robots(), so printing a second one creates conflicting signals. The snippet instead adds a wp_robots filter that sets noindex, follow on thin archives and enables large image and text snippets.

How to use the WordPress Meta Tag Generator

  1. Set a unique function prefix and your theme or plugin text domain.
  2. Choose how the meta description is generated and write a fallback description of 120–160 characters.
  3. Pick robots rules, theme color, author and Open Graph options, and paste any verification codes — the full <meta> tag works too.
  4. Check the HTML preview for the front page and a single post, then copy the snippet into your child theme’s functions.php or a small plugin.
  5. View the page source of your site to confirm the tags appear once in <head>.

Example

What the snippet prints on a single post:

<meta name='robots' content='max-image-preview:large, max-snippet:-1, max-video-preview:-1' />
<meta name="description" content="How to register a custom post type with full labels and REST support." />
<meta name="author" content="Jane Doe" />
<meta name="theme-color" content="#4f46e5" />
<meta property="og:type" content="article" />
<meta property="og:title" content="Custom Post Types Explained – My Site" />

Why the snippet checks for SEO plugins

If Yoast SEO, Rank Math, SEOPress or All in One SEO is installed later, two sets of descriptions and Open Graph tags would be printed. The optional guard checks the constants each plugin defines — WPSEO_VERSION, RANK_MATH_VERSION, SEOPRESS_VERSION and AIOSEO_VERSION — and steps aside automatically.

Good practice

  • Write real excerpts for important posts. The automatic fallback is fine, but a hand-written summary earns more clicks — the Meta Description Generator helps.
  • Google uses the description as a snippet suggestion, not a ranking factor. It may still rewrite it to match the query.
  • Verification tags only need to be on the home page, so the snippet prints them there only.
  • For full Open Graph and Twitter control per page, see the Open Graph Generator or more snippets in functions.php Snippets.

Frequently Asked Questions

How is this different from the SEO Meta Tag Generator?

The SEO Meta Tag Generator creates static HTML tags for one page. This tool generates WordPress PHP that outputs the right tags for every page automatically, using post excerpts, featured images and WordPress conditionals.

Where do I paste the code?

In a child theme’s functions.php, a site-specific plugin or a code-snippets plugin. Do not edit a parent theme directly — updates overwrite it.

Why use the wp_robots filter instead of printing a robots tag?

WordPress 5.7+ already prints a robots meta tag (with max-image-preview:large, plus noindex when search engines are discouraged). Filtering that array keeps a single, consistent tag.

Does the description work for WooCommerce products?

Yes. Products are a singular post type, so the product’s short description (stored as the excerpt) is used, falling back to the start of the long description.

Will the tags be duplicated if I install Yoast later?

Not if “Skip when an SEO plugin is active” is ticked. The functions return early when one of the major SEO plugins is detected.