Skip to content

Commit

Permalink
Allow redundant hyphens
Browse files Browse the repository at this point in the history
  • Loading branch information
samiahmedsiddiqui committed Nov 26, 2021
1 parent 09d0300 commit 6614c17
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ function yasglobal_allow_uppercaps() {
add_filter( 'custom_permalinks_allow_caps', 'yasglobal_allow_uppercaps' );
```

### Allow Redundant Hyphens

To allow redundant hyphens, please add below-mentioned line in your theme `functions.php`:

```php
function yasglobal_redundant_hyphens() {
return true;
}
add_filter( 'custom_permalinks_redundant_hyphens', 'yasglobal_redundant_hyphens' );
```

### Manipulate Permalink Before Saving

To make changes in permalink before saving, please use `custom_permalink_before_saving` filter. Here is an example to see how it works.
Expand Down
11 changes: 10 additions & 1 deletion includes/class-custom-permalinks-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,16 @@ private function sanitize_permalink( $permalink, $language_code ) {
$permalink = preg_replace( '|-+|', '-', $permalink );
$permalink = str_replace( '-/', '/', $permalink );
$permalink = str_replace( '/-', '/', $permalink );
$permalink = trim( $permalink, '-' );

/*
* Avoid trimming hyphens if filter returns `false`.
*
* @since 2.4.0
*/
$trim_hyphen = apply_filters( 'custom_permalinks_redundant_hyphens', false );
if ( ! is_bool( $trim_hyphen ) || ! $trim_hyphen ) {
$permalink = trim( $permalink, '-' );
}

return $permalink;
}
Expand Down

0 comments on commit 6614c17

Please sign in to comment.