Title: Getting Default Values from Shortcode Attributes
Last modified: April 4, 2019

---

# Getting Default Values from Shortcode Attributes

 *  [creativepassion](https://wordpress.org/support/users/creativepassion/)
 * (@creativepassion)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/getting-default-values-from-shortcode-attributes-3/)
 * I want to include the “hotelmotel” attribute in the shortcode and for it to display
   on the mailed form, but I’ve got something wrong. Can someone help please.
 * There’s a great explanation how to do it here:
    [https://contactform7.com/getting-default-values-from-shortcode-attributes/](https://contactform7.com/getting-default-values-from-shortcode-attributes/)
 * **Added this to the bottom of functions.php:**
 * /* Add hotelmotel shortcode attribute */
    add_filter( ‘shortcode_atts_wpcf7’,‘
   custom_shortcode_atts_wpcf7_filter’, 10, 3 );
 * function custom_shortcode_atts_wpcf7_filter( $out, $pairs, $atts ) {
    $my_attr
   = ‘hotelmotel’;
 *  if ( isset( $atts[$my_attr] ) ) {
    $out[$my_attr] = $atts[$my_attr]; }
 *  return $out;
    }
 * **Added this into the Mail message body:**
 * [hotelmotel]
 * **Added this to the form:**
 * [hidden text hotelmotel default:shortcode_attr]
 * **Added this on the page where we want the form to appear:**
 * [contact-form-7 id=”38″ title=”Contact form – Andy” hotelmotel=”Empire Hotel 
   Gympie”]
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fgetting-default-values-from-shortcode-attributes-3%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/getting-default-values-from-shortcode-attributes-3/#post-11390994)
 * > Added this to the form:
   > [hidden text hotelmotel default:shortcode_attr]
 * [The name of a form-tag is the second word in the tag](https://contactform7.com/tag-syntax/).
   In the case of the tag above, “text” is its name.
 *  Thread Starter [creativepassion](https://wordpress.org/support/users/creativepassion/)
 * (@creativepassion)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/getting-default-values-from-shortcode-attributes-3/#post-11394221)
 * Thanks. But it’s still not working sorry. Help please!
 * **functions.php:**
 * /* Add hotelmotel shortcode attribute */
    add_filter( ‘shortcode_atts_wpcf7’,‘
   custom_shortcode_atts_wpcf7_filter’, 10, 3 );
 * function custom_shortcode_atts_wpcf7_filter( $out, $pairs, $atts ) {
    $my_attr
   = ‘hotelmotel’;
 * if ( isset( $atts[$my_attr] ) ) {
    $out[$my_attr] = $atts[$my_attr]; }
 * return $out;
    }
 * **Mail message body:**
    [hotelmotel]
 * **Form:**
    [hidden hotelmotel default:shortcode_attr]
 * **Page:**
    [contact-form-7 id=”38″ title=”Contact form – Andy” hotelmotel=”Empire
   Hotel Gympie”]
 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/getting-default-values-from-shortcode-attributes-3/#post-11394774)
 * What other plugins and theme do you use on the site?
 *  Thread Starter [creativepassion](https://wordpress.org/support/users/creativepassion/)
 * (@creativepassion)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/getting-default-values-from-shortcode-attributes-3/#post-11394965)
 * I’ve tried deactivating every plugin except Contact Form 7. But still no luck
   🙁
 * Thanks for your help!
 * WP 4.9.10
    Theme: DiviVersion 3.12.2 By Elegant Themes
 * Admin Post Navigation 2.1 By Scott Reilly
    BackupBuddy 6.1.0.2 By iThemes Contact
   Form 7 5.1.1 By Takayuki Miyoshi 🙂 Divi Booster By 1.2.4 Dan Mossop Divi Children
   2.0.7.1 By Luis Alejandre Duplicate Post 3.2.2 By Enrico Battocchi Elegant Themes
   Updater 1.1 By Elegant Themes Google Sitemap 3.1.7 by BestWebSoft By BestWebSoft
   Insert Pages 3.4.5 By Paul Ryan Intuitive Custom Post Order 3.1.2 By hijiri List
   category posts 0.79 By Fernando Briano Really Simple SSL 3.15 By Rogier Lankhorst
   Yoast Version 10.1.3
 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/getting-default-values-from-shortcode-attributes-3/#post-11395140)
 * I don’t see any mistakes in the current configuration you’ve posted and have 
   no idea why it isn’t working. Not sure, but my gut tells there is something wrong
   around the functions.php code.
 *  Thread Starter [creativepassion](https://wordpress.org/support/users/creativepassion/)
 * (@creativepassion)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/getting-default-values-from-shortcode-attributes-3/#post-11395159)
 * Would the child functions.php help?
 * <?php
    /** * Functions – Child theme custom functions */
 * /*****************************************************************************************************************
   
   Caution: do not remove this or you will lose all the customization capabilities
   created by Divi Children plugin */ require_once(‘divi-children-engine/divi_children_engine.
   php’); /****************************************************************************************************************/
 * /**
    * Patch to fix Divi issue: Duplicated Predefined Layouts. */ remove_action(‘
   admin_init’, ‘et_pb_update_predefined_layouts’ ); function Divichild_pb_update_predefined_layouts(){
   if ( ‘on’ === get_theme_mod( ‘et_pb_predefined_layouts_updated_2_0’ ) ) { return;}
   if ( ! get_theme_mod( ‘et_pb_predefined_layouts_added’ ) OR ( ‘on’ === get_theme_mod(‘
   et_pb_predefined_layouts_added’ ) )) { et_pb_delete_predefined_layouts(); } et_pb_add_predefined_layouts();
   set_theme_mod( ‘et_pb_predefined_layouts_updated_2_0’, ‘on’ ); } add_action( ‘
   admin_init’, ‘Divichild_pb_update_predefined_layouts’ );
 * function mycustom_featured_width( ) { return 160; /* Custom featured post image
   width */ }
    add_filter( ‘et_pb_blog_image_width’, ‘mycustom_featured_width’);
   add_filter( ‘et_pb_index_blog_image_width’, ‘mycustom_featured_width’);
 * function mycustom_featured_height( ) { return 130; /* Custom featured post image
   height */ }
    add_filter( ‘et_pb_blog_image_height’, ‘mycustom_featured_height’);
   add_filter( ‘et_pb_index_blog_image_height’, ‘mycustom_featured_height’);
 * function mycustom_featured_size( $image_sizes ) {
    $custom_size = mycustom_featured_width().‘
   x’ . mycustom_featured_height(); $image_sizes[$custom_size] = ‘et-pb-post-main-
   image-thumbnail’; return $image_sizes; } add_filter( ‘et_theme_image_sizes’, ‘
   mycustom_featured_size’ );
 * /* Index & archive */
    function wpt_index_thumbnail_width( $width ) { if( !is_single()){
   return 150; //index thumbnail width in pixels } else { return $width; } } add_filter(‘
   et_pb_index_blog_image_width’, ‘wpt_index_thumbnail_width’); function wpt_index_thumbnail_height(
   $height ) { if( !is_single() ) { return 212; //index thumbnail height in pixels}
   else { return $height; } } add_filter( ‘et_pb_index_blog_image_height’, ‘wpt_index_thumbnail_height’);
 * /* Add hotelmotel shortcode attribute */
    add_filter( ‘shortcode_atts_wpcf7’,‘
   custom_shortcode_atts_wpcf7_filter’, 10, 3 );
 * function custom_shortcode_atts_wpcf7_filter( $out, $pairs, $atts ) {
    $my_attr
   = ‘hotelmotel’;
 * if ( isset( $atts[$my_attr] ) ) {
    $out[$my_attr] = $atts[$my_attr]; }
 * return $out;
    }
 * ?>

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Getting Default Values from Shortcode Attributes’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

## Tags

 * [attribute](https://wordpress.org/support/topic-tag/attribute/)
 * [default](https://wordpress.org/support/topic-tag/default/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [value](https://wordpress.org/support/topic-tag/value/)

 * 6 replies
 * 2 participants
 * Last reply from: [creativepassion](https://wordpress.org/support/users/creativepassion/)
 * Last activity: [7 years, 2 months ago](https://wordpress.org/support/topic/getting-default-values-from-shortcode-attributes-3/#post-11395159)
 * Status: not resolved