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: Setting a specific page to be noindexed
function custom_noindex() {
if ( is_page( 'about-us' ) ) {
echo '';
}
}
add_action( 'wp_head', 'custom_noindex' );
// Example 2: Preventing indexing of search results pages
function prevent_search_indexing() {
if ( is_search() ) {
echo '';
}
}
add_action( 'wp_head', 'prevent_search_indexing' );
// Example 3: Conditionally setting noindex for specific post types
function conditional_noindex_post_types() {
$post_types = array( 'post', 'product' );
if ( is_singular( $post_types ) ) {
echo '';
}
}
add_action( 'wp_head', 'conditional_noindex_post_types' );