Monat: Oktober 2015

Bugfix contactform7 do_shortcode with special tags

4. Oktober 2015 - PHP, wordpress

Recently I tried to use contact form 7 to display a contact form which contains a special email tag (e.g. [_post_title] ) in the subject field with do_shortcode(). It simply didn't work. I tried this fix but without success. The special tag wasn't resolved, either . Maybe there are some limitations in the way, WordPress has implemented do_shortcode(). Some information about that is here Nevertheless, I had to solve my problem and this is my hack:
// this goes inside the loop
$my_post_title=get_the_title( get_the_ID());
ob_start();
echo do_shortcode('[contact-form-7 id="2070" title="Product inquiery"]');
$unresolved=ob_get_contents();
ob_end_clean();
echo preg_replace('/_post_title/',$my_post_title,$unresolved);
As you can see, I had to give up the idea of using the special tag [_post_title] inside contact form 7 and I'm using the string "_post_title" in my form,  instead. Then php output buffer and preg_replace will do the work for me.