Home / Admin / Using Smart Tags in Your WordPress Rewrite Rules
Duplicate Snippet

Embed Snippet on Your Site

Using Smart Tags in Your WordPress Rewrite Rules

<10
Code Preview
php
<?php
/**
 * Using Smart Tags in WordPress rewrite rules
 *
 * @link https://wpforms.com/developers/how-to-use-smart-tags-in-your-wordpress-rewrite-rules/
 */
 
// Register custom query var
function register_query_var( $wp ) {
    parse_str( $wp->matched_query, $url );
 
    if ( ! isset( $url[ 'email_address' ] ) ) {
        return;
    }
 
    $wp->set_query_var( 'email_address', $url[ 'email_address' ] );
}
 
add_filter( 'parse_request', 'register_query_var', 9, 1 );
 
// Replace query var in WPForms smat tags
function my_process_smart_tags( $content ) {
 
    // Query string var smart tags.
    preg_match_all( "/\{query_var key=\"(.+?)\"\}/", $content, $query_vars );
 
    if ( ! empty( $query_vars[1] ) ) {
        foreach ( $query_vars[1] as $key => $query_var ) {
            $value   = get_query_var( $query_var ); // phpcs:ignore
            $content = str_replace( $query_vars[0][ $key ], strip_shortcodes( $value ), $content );
        }
 
    }
 
    return $content;
 
}
add_filter( 'wpforms_process_smart_tags', 'my_process_smart_tags', 9, 1 );

Comments

Add a Comment