Skip to content

Instantly share code, notes, and snippets.

@khromov
Created April 11, 2014 21:27
Show Gist options
  • Save khromov/10502980 to your computer and use it in GitHub Desktop.
Save khromov/10502980 to your computer and use it in GitHub Desktop.
Adding custom shortcodes to Contact Form 7
<?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