25% off ProSNIPC25OFF

Add Custom Meta Tag to Head

Outputs one or more custom name or property meta tags into the page head; edit the array to add or remove tags without touching theme files.

PHPby SnipCraft
php
<?php
if ( ! function_exists( 'scseed_custom_meta_tags' ) ) :
function scseed_custom_meta_tags() {
    // Add, remove, or edit entries in this array.
    // Use 'name' OR 'property' (not both) per entry.
    $meta_tags = array(
        array( 'name' => 'theme-color',  'content' => '#ffffff' ),
        array( 'name' => 'referrer',     'content' => 'strict-origin-when-cross-origin' ),
        // array( 'property' => 'fb:app_id', 'content' => '000000000000000' ),
    );
    foreach ( $meta_tags as $tag ) {
        if ( ! empty( $tag['name'] ) && ! empty( $tag['content'] ) ) {
            echo '<meta name="' . esc_attr( $tag['name'] ) . '" content="' . esc_attr( $tag['content'] ) . '">' . PHP_EOL;
        } elseif ( ! empty( $tag['property'] ) && ! empty( $tag['content'] ) ) {
            echo '<meta property="' . esc_attr( $tag['property'] ) . '" content="' . esc_attr( $tag['content'] ) . '">' . PHP_EOL;
        }
    }
}
add_action( 'wp_head', 'scseed_custom_meta_tags' );
endif;
#custom#head#html#meta#seo