Created
April 11, 2014 21:27
-
-
Save khromov/10502980 to your computer and use it in GitHub Desktop.
Adding custom shortcodes to Contact 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 | |
/* | |
Plugin Name: Contact Form 7 Post Title shortcode | |
Plugin URI: | |
Description: Use in form: [post_title thetitle] - use in email (to get value): [thetitle] | |
Version: 2014.04.07 | |
Author: khromov | |
Author URI: http://profiles.wordpress.org/khromov/ | |
License: GPL2 | |
*/ | |
add_action('plugins_loaded', function() | |
{ | |
if(function_exists('wpcf7_add_shortcode')) | |
{ | |
/** Post title shortcode **/ | |
wpcf7_add_shortcode('post_title', function($tag) | |
{ | |
if (!is_array($tag)) return ''; | |
$name = $tag['name']; | |
if (empty($name)) return ''; | |
$html = '<input type="hidden" name="' . $name . '" value="'. get_the_title() .'" />'; | |
return $html; | |
}, true); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment