Last active
June 8, 2018 01:59
-
-
Save morgyface/38f47d64f9d5838efbc96f67d3f0fb47 to your computer and use it in GitHub Desktop.
WordPress | Contact Form 7 | Display any forms that match the page title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 . '"]') ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note. This Gist was updated in February 2017. I previously used get_posts but realised it was unnecessary and overly bulky.