Function Signature:
noindex
Function Description:
Displays a `noindex` meta tag if required by the blog configuration.
Function Examples:
⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Example 1: Prevent a specific page from being indexed by search engines
function custom_noindex() {
if ( is_page( 'example-page' ) ) {
echo '';
}
}
add_action( 'wp_head', 'custom_noindex' );
// Example 2: Exclude a category archive page from search engine indexing
function exclude_category_noindex() {
if ( is_category( 'uncategorized' ) ) {
echo '';
}
}
add_action( 'wp_head', 'exclude_category_noindex' );
// Example 3: Set a noindex tag for all attachment pages to avoid duplicate content issues
function noindex_attachment_pages() {
if ( is_attachment() ) {
echo '';
}
}
add_action( 'wp_head', 'noindex_attachment_pages' );