Title: Pre-fill with PHP code
Last modified: August 31, 2016

---

# Pre-fill with PHP code

 *  Resolved [Wouters](https://wordpress.org/support/users/wouters/)
 * (@wouters)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/pre-fill-with-php-code/)
 * Hi, I’m trying to pre-fill a input field with some php code.
    I have looked around
   and found you need to make your own function.
 * So, i have this now:
 *     ```
       function cf7_add_city() {
            global $post;
            $terms = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name;
            return $terms;
       }
       add_shortcode('CF7_ADD_CITY', 'cf7_add_city');
       ```
   
 * and then in my contact form I have:
    `[dynamictext "cf7_add_city"]`
 * but noting shows up? I would like too show the custom taxonomy slug, not the 
   page slug, in the field
 * [https://wordpress.org/plugins/contact-form-7-dynamic-text-extension/](https://wordpress.org/plugins/contact-form-7-dynamic-text-extension/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [Wouters](https://wordpress.org/support/users/wouters/)
 * (@wouters)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/pre-fill-with-php-code/#post-7053493)
 * Fixed it my self. Turns out the echo at the end should be a return.
 *     ```
       function cf7_add_city() {
            global $post;
            $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); return $term->name;
   
       }
       add_shortcode('CF7_ADD_CITY', 'cf7_add_city');
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Pre-fill with PHP code’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7-dynamic-text-extension/assets/icon-256x256.
   png?rev=3019574)
 * [Contact Form 7 - Dynamic Text Extension](https://wordpress.org/plugins/contact-form-7-dynamic-text-extension/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7-dynamic-text-extension/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7-dynamic-text-extension/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7-dynamic-text-extension/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7-dynamic-text-extension/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7-dynamic-text-extension/reviews/)

## Tags

 * [development](https://wordpress.org/support/topic-tag/development/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 1 reply
 * 1 participant
 * Last reply from: [Wouters](https://wordpress.org/support/users/wouters/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/pre-fill-with-php-code/#post-7053493)
 * Status: resolved