Skip to content

badasswp/redirect-duplicate-posts

Repository files navigation

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.

You can also get the latest version from any of our release tags.

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:

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_regex_pattern

This custom hook (filter) provides the ability to filter the regex pattern. For e.g you can do:

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.

About

Redirect duplicate post URLs to original URL.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages