Shoora
7/1/2016 - 11:45 AM

WordPress | Contact Form 7 | Display any forms that match the page title

WordPress | Contact Form 7 | Display any forms that match the page title

<?php
// If there is a CF7 form with the same name as the current page let us display it.
$current_page_title = get_the_title();
$cf7form = get_page_by_title( $current_page_title, OBJECT, 'wpcf7_contact_form' );
if ( $cf7form ) {
    $formid = $cf7form->ID;
    $formtitle = $cf7form->post_title;
    echo( do_shortcode('[contact-form-7 id="' . $formid . '" title="' . $formtitle . '"]') );
}
?>