Created
January 22, 2018 21:30
-
-
Save EdenK/21d656ca8f172b92603e9d11d9d40370 to your computer and use it in GitHub Desktop.
Wordpress: Contact form 7, Add form tag (shortcode) current url example
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 | |
/** | |
* Wordpress: Contact form 7, Add form tag (shortcode) current url example | |
*/ | |
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_current_url' ); | |
function wpcf7_add_form_tag_current_url() { | |
// Add shortcode for the form [current_url] | |
wpcf7_add_form_tag( 'current_url', | |
'wpcf7_current_url_form_tag_handler', | |
array( | |
'name-attr' => true | |
) | |
); | |
} | |
// Parse the shortcode in the frontend | |
function wpcf7_current_url_form_tag_handler( $tag ) { | |
global $wp; | |
$url = home_url( $wp->request ); | |
return '<input type="hidden" name="'.$tag['name'].'" value="'.$url.'" />'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment