Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ The following JSON is the default configuration for the module and can be overri
"altis": {
"modules": {
"seo": {
"enabled": true
},
"redirects": true
"enabled": true,
"redirects": true,
"allow_indexing": true
}
}
}
}
}
```

### Configuration Options

- **enabled** (bool): Enable or disable the SEO module. Default: `true`
- **redirects** (bool): Enable or disable the redirects functionality. Default: `true`
- **allow_indexing** (bool): Allow search engines to index the site. Default: `true` for production environments, `false` for all other environments (development, staging, etc.). When set to `false`, the robots.txt file will include directives to disallow indexing.
17 changes: 17 additions & 0 deletions inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ function bootstrap( Module $module ) {
if ( $settings['redirects'] ) {
add_action( 'muplugins_loaded', __NAMESPACE__ . '\\load_redirects', 0 );
}

// Disallow indexing if the allow_indexing setting is false.
if ( ! ( $settings['allow_indexing'] ?? true ) ) {
add_filter( 'robots_txt', __NAMESPACE__ . '\\disallow_indexing', 10, 2 );
}
}

/**
Expand All @@ -32,3 +37,15 @@ function bootstrap( Module $module ) {
function load_redirects() {
require_once Altis\ROOT_DIR . '/vendor/humanmade/hm-redirects/hm-redirects.php';
}

/**
* Disallow indexing in robots.txt.
*
* @param string $output The robots.txt output.
* @param string $public Whether the site is public.
* @return string Modified robots.txt output.
*/
function disallow_indexing( string $output, string $public ) : string {
$output .= "\nUser-agent: *\nDisallow: /\n";
return $output;
}
1 change: 1 addition & 0 deletions load.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
$default_settings = [
'enabled' => true,
'redirects' => true,
'allow_indexing' => Altis\get_environment_type() === 'production',
];
$options = [
'defaults' => $default_settings,
Expand Down