Last active
December 17, 2022 15:53
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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