Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active December 17, 2022 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/e74f559a523259141a7e95c25a7327fa to your computer and use it in GitHub Desktop.
Save cliffordp/e74f559a523259141a7e95c25a7327fa to your computer and use it in GitHub Desktop.
Redirection plugin: Add support for additional shortcodes. Working as of Redirection v5.3.5
<?php
/**
* Redirection plugin: Add support for additional shortcodes.
*
* Adding support for: [my_shortcode]
* !!!You CANNOT call `do_shortcode()` within this function. Just call the shortcode's function directly.
*
* @link https://gist.github.com/cliffordp/e74f559a523259141a7e95c25a7327fa This snippet.
* @link https://redirection.me/support/dynamic-urls/
* @link https://github.com/johngodley/redirection/blob/5.3.6/models/url/url-transform.php#L31
*/
add_filter( 'redirection_shortcodes', function ( array $supported_shortcodes ) {
return array_merge( [ 'my_shortcode' ], $supported_shortcodes );
} );
add_filter( 'redirection_url_transform', function (
string $value,
string $tag,
$attrs,
$content
) {
if ( 'my_shortcode' === $tag ) {
if ( function_exists( 'my_shortcode' ) ) {
$value = my_shortcode();
} else {
$value = '';
}
}
return $value;
}, 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment