Full Coonditional Method
The code snippet below has 2 hooks:
- add noindex to all GD pages
- add noindex to some GD pages, with a comprehensive list of conditionals
It should work with most SEO plugins.
/**
* Add noindex, nofollow robots meta directive on all GD pages.
*/
add_filter( 'wp_robots', 'gdsnippet_no_robots_all', 999, 1 );
function gdsnippet_no_robots_all( $robot_directives ) {
if ( function_exists( 'geodir_is_geodir_page' ) && geodir_is_geodir_page() )
{
return [
'noindex' => true,
'nofollow' => true,
];
}
return $robot_directives;
}
/**
* Add noindex, nofollow robots meta directive on some GD pages.
*/
add_filter( 'wp_robots', 'gdsnippet_no_robots_some', 999, 1 );
function gdsnippet_no_robots_some( $robot_directives ) {
// Bail early if geodir_is_page() doesn't exists.
if ( ! function_exists( 'geodir_is_page' ) ) {
return $robot_directives;
}
/**
* Combine conditionals with "||" (OR) in-between.
* Ex: if ( geodir_is_page( 'single ) || geodir_is_page( 'archive ) ).
*/
if (
// GD main pages.
geodir_is_page( 'search' )
|| geodir_is_page( 'archive' ) // All archives.
|| geodir_is_page( 'post_type' ) // Same as above, doesn't include taxonomy archives.
|| geodir_is_page( 'location' )
|| geodir_is_page( 'single' )
// Add listing pages.
|| geodir_is_page( 'add-listing' ) // Includes edit-listing pages.
|| geodir_is_page( 'edit-listing' ) // Only edit-listing pages.
|| geodir_is_page( 'listing-success' )
|| geodir_is_page( 'preview' )
// Others.
|| geodir_is_page( 'author' )
|| geodir_is_page( 'compare' )
)
// If any of the above is true, return a no-index robots meta.
{
return [
'noindex' => true,
'nofollow' => true,
];
}
// If not, don't interfere.
return $robot_directives;
}
PHP
Short Snippet
The following snippet will de-index all single listing pages.
It’s possible for your developer to extend it to include others, like search, archives, etc.
add_filter( 'wp_robots', 'gdsnippet_no_robots', 999, 1 );
function gdsnippet_no_robots( $robot_directives ) {
if ( function_exists( 'geodir_is_page' ) && geodir_is_page( 'single' ) )
{
return [
'noindex' => true,
'nofollow' => true,
];
}
return $robot_directives;
}
PHP