https://github.com/badasswp/redirect-duplicate-posts
Redirect duplicate post URLs to original URL.
https://github.com/badasswp/redirect-duplicate-posts
duplicate plugin posts seo wordpress
Last synced: 6 months ago
JSON representation
Redirect duplicate post URLs to original URL.
- Host: GitHub
- URL: https://github.com/badasswp/redirect-duplicate-posts
- Owner: badasswp
- License: gpl-3.0
- Created: 2025-11-11T07:08:41.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2025-11-11T08:03:29.000Z (8 months ago)
- Last Synced: 2025-11-11T09:11:50.711Z (8 months ago)
- Topics: duplicate, plugin, posts, seo, wordpress
- Language: PHP
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redirect-duplicate-posts
Redirect Duplicate Posts
For e.g. `https://example.com/hello-world-2` -> `https://example.com/hello-world`
## Download
Download from [WordPress plugin repository](https://wordpress.org/plugins/redirect-duplicate-posts/).
You can also get the latest version from any of our [release tags](https://github.com/badasswp/redirect-duplicate-posts/releases).
## Why Redirect Duplicate Posts?
Working with translation plugins can be sometimes stressful, especially if your post or article is erroneously translated into multiple copies which you never intended.
This plugin helps redirect users away from duplicate posts and articles to the original post URL, thereby improving Search Engine Optimization for your WP website.
### Hooks
#### `redirect_duplicate_posts_exclude_urls`
This custom hook (filter) provides the ability to exclude a specific URL from redirection:
```php
add_filter( 'redirect_duplicate_posts_exclude_urls', [ $this, 'filter_exclude_urls' ], 10, 1 );
public function filter_exclude_urls( $urls ): array {
$urls[] = 'https://exmaple.com/hello-world-2';
return $urls;
}
```
**Parameters**
- urls _`{string[]}`_ List of URLs to exclude.
#### `redirect_duplicate_posts_redirect_url`
This custom hook (filter) provides the ability to filter the redirect URL. For e.g you can do:
```php
add_filter( 'redirect_duplicate_posts_redirect_url', [ $this, 'filter_redirect_url' ], 10, 3 );
public function filter_redirect_url( $redirect_url, $current_url, pattern ): string {
if ( 'https://example.com/hello-world-2' === $redirect_url ) {
error_log( 'Error: Redirect URL not working as expected' );
}
}
```
**Parameters**
- redirect_url _`{string}`_ Redirect URL. By default, this would be the Redirect URL.
- current_url _`{string}`_ Current URL. By default, this would be the Current URL of the duplicate post.
- pattern _`{string}`_ Regex Pattern. By default, this would be a regex pattern to help with matching duplicate posts.
#### `redirect_duplicate_posts_regex_pattern`
This custom hook (filter) provides the ability to filter the regex pattern. For e.g you can do:
```php
add_filter( 'redirect_duplicate_posts_regex_pattern', [ $this, 'filter_regex_pattern' ], 10, 1 );
public function filter_regex_pattern( $pattern ): string {
return '/-(?:[2-9])\/?$/';
}
```
**Parameters**
- pattern _`{string}`_ Regex Pattern. By default this would be a regex pattern to help with matching duplicate posts.
---
## Contribute
Contributions are __welcome__ and will be fully __credited__. To contribute, please fork this repo and raise a PR (Pull Request) against the `master` branch.