Created
August 9, 2011 06:25
-
-
Save bainternet/1133507 to your computer and use it in GitHub Desktop.
add current page url tag to content form 7
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 | |
/* | |
* add this to your theme's functions.php file | |
*/ | |
wpcf7_add_shortcode('sourceurl', 'wpcf7_sourceurl_shortcode_handler', true); | |
function wpcf7_sourceurl_shortcode_handler($tag) { | |
if (!is_array($tag)) return ''; | |
$name = $tag['name']; | |
if (empty($name)) return ''; | |
$html = '<input type="hidden" name="' . $name . '" value="http://' . $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"] . '" />'; | |
return $html; | |
} | |
/* | |
* open your contact form and in the form part add: | |
"[sourceurl thesource]" | |
* | |
* and in the email part add: | |
"Source URL: <a href="[thesource]">[thesource]</a><br />" | |
*/ | |
and you are done |
Also update on row #9:
$name = $tag->name;
instead of
$name = $tag['name'];
Thanks a lot
With @danstramer reviews this code works. Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just a heads up, because of recent changes in wpcf7 to version 4.8, please update
is_array > is_object
and
wpcf7_add_shortcode > wpcf7_add_form_tag
More here:
https://wordpress.org/support/topic/wpcf7_add_form_tag-not-working/
Thanks
Dan