I'm using a contact form 7 for the contact forms. I have a page for a doctor for example, and it has it's own form on the same page. How can I display the title of that page into the input field or select field on the contact form 7?
I did some research for dynamic data on contact form 7 and I found this https://wordpress.org/plugins/contact-form-7-dynamic-text-extension/
I put the following code into the form but it's not retrieving the page title:
[dynamictext dynamicname “CF7_get_post_var key=’title'”]
Any help is very much appreciated.
To use shortcode inside the wpcf7 forms, an easy way is "Berenis" solution, but with an important change.
Instead of add_shortcode( 'cf7_extra_fields', 'cf7_extra_fields_func' ); should be wpcf7_add_shortcode( 'cf7_extra_fields', 'cf7_extra_fields_func', true );.
Remaining code can be same, on functions.php:
wpcf7_add_shortcode( 'cf7_extra_fields', 'cf7_extra_fields_func', true );
function cf7_extra_fields_func( $atts ) {
$html = '';
$html .= '<input type="hidden" name="page-title" value="'.get_the_title().'" />';
$html .= '<input type="hidden" name="page-url" value="'.get_the_permalink().'" />';
return $html;
}
On contact form, use: [cf7_extra_fields], on email fields use: [page-title] and [page-url].
This worked for me, without any issues.
a year late, but I just saw it. I suppose you have already solved it. The error is because the shortcode has wrong characters. The correct thing is like this:
[dynamictext dynamicname "CF7_get_post_var key='title'"]
Regards!
Put this to functions.php
add_shortcode( 'cf7_extra_fields', 'cf7_extra_fields_func' );
function cf7_extra_fields_func( $atts ) {
$html = '';
$html .= '<input type="hidden" name="page-title" value="<'.get_the_title().'">';
$html .= '<input type="hidden" name="page-url" value="<'.get_the_permalink().'">';
return $html;
}
Then when editing contact form add this shortcode inside [cf7_extra_fields]
When passing form fields to email use [page-title] and [page-url]
No plugin needed
Did you try with jquery/js ? like jQuery("#field_id").val("<?php echo get_the_title(); ?>"); . you can try this code in the page where the form is using.
Related
I want to send HTML content using contact form 7, but HTML code is not working direct send HTML tag in email. so how can I send this type of message using the hook or any way?
I am using hook "wpcf7_posted_data" to append my extra HTML tag in body text.
I want to send extra HTML format data before send an email.
function action_wpcf7_posted_data( $array ) {
$html .= '<table>';
$html .='<tr><td>'.$product->get_Name().'</td></tr>';
$html .='<tr><td>'.$display.'</td></tr>';
$html .='<tr><td>Qty : '.$ProductQty.'</td></tr>';
$html .= '</table>';
$value = $array['message'];
if( !empty( $value ) ){
$array['message'] = $value."<br><br>".$html;
}
return $array;
}
add_filter( 'wpcf7_posted_data', 'action_wpcf7_posted_data', 10, 1 );
If you are trying to append data to the Contact Form 7 email HTML. The below code will do that. However, it appears that you're using some other variables that I wasn't sure where you were getting them from. All of the submitted form fields will be in $posted_data in my function below. You can trigger the process on the existence of a field, or just run it every time. You can also use global $product and get variables to complete your table.
add_action( 'wpcf7_before_send_mail', 'he_append_to_email_body' );
function he_append_to_email_body( $contact_form ) {
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
}
if (isset($posted_data['the_field_you_want_to_trigger_this'])) { // Check that your field is present in your form.
/**
* ToDo:
* Get your product and display and other variables here to put into the table.
*/
$html = '<table>';
$html .='<tr><td>'.$product->get_Name().'</td></tr>';
$html .='<tr><td>'.$display.'</td></tr>';
$html .='<tr><td>Qty : '.$ProductQty.'</td></tr>';
$html .= '</table>';
// Get the existing output from the CF7 email
$mail = $contact_form->prop( 'mail' );
// Append your data after the existing
$mail['body'] .= $html;
// Update the mail
$contact_form->set_properties(array('mail' => $mail));
}
return;
}
You don't need your user to insert HTML in the form by himself. So you need to set layout for the sent message in the form MAIL TAB itself, and check the "Use HTML content type" bellow the Message body field.
You are allowed to compose your HTML, but beware that Mail protocols and clients doesn't read all HTML tags or even all CSS.
Check this link for how to create a HTML E-mail body message: https://www.campaignmonitor.com/dev-resources/guides/coding-html-emails/
And this for allowed CSS: https://www.campaignmonitor.com/css/
You may also send the form to another e-mail address, check the Use Mail (2)
"is an additional mail template often used as an autoresponder".
Check Contact Form 7 Documentation: https://contactform7.com/setting-up-mail/
Regards.
H
I am using ACF Advanced Custom Fields Plugin to create custom fields. I have a field which I would like to output in place of the default WordPress featured image. Basically, I'm replacing the default WordPress featured image functionality with the custom field. The custom field contains a piece of html code which contains 3 images - 1 background image and two images on top of the image (I'm using CSS to align them properly.) That's the reason I want to use the custom field option.
I really don't know how to solve this and I really hope that somebody has a solution.
you have to add_filter to the post_thumbnail_html function
here is an example that you have to change the $html variable as you need
functions.php
add_filter('post_thumbnail_html', 'change_post_thumbnail_html', 10, 5);
function change_post_thumbnail_html($html, $post_id, $post_thumbnail_id, $size, $attr)
{
global $post;
$post_field_1 = get_field('first-image',$post->ID);
$post_field_2 = get_field('second-image',$post->ID);
$html = '<div class="acf-thumbnail_container">';
$html .= '<div class="acf-first_thumbnail">';
$html .= $post_field_1; // if it return an array you can use wp_get_attachment_image($post_field_1); to generate image
$html .= '</div>';
$html .= '<div class="acf-second_thumbnail">';
$html .= $post_field_2;
$html .= '</div>';
$html .= '</div>';
return $html;
}
I'm trying to insert a button to show at the end of each post on Wordpress in which the link it goes to is defined by a setup using the custom fields plugin. When creating each post, I am able to select the link I wish to display.
Here is the code I have which I know is wrong but I was hoping someone could help here.
function wpb_after_post_content($content){
if (is_single()) {
$content .= 'Contact Franchise →';
}
return $content;
}
add_filter( "the_content", "wpb_after_post_content" );
I assume $franchise_profile_url is a variable and you should concatenate it in the string like this
$content .= 'Contact Franchise →';
function afterContent($content) {
if(!is_feed() && !is_home()) {
$content.= "<div class='footNote'>";
$content.= "<h4>Click the below button if you like it:</h4>";
$content.= "<p><a href='#'>LIKE</a></p>";
$content.= "</div>";
}
return $content;
}
add_filter ('the_content', 'afterContent');
Use the above function. It will help you to achieve what you need.
Thanks for the help here, however, that code simply links back to the post itself and isn't pulling in the URL as set on the post using custom fields. This is the code I had set up before which was working on a default post setup but now I wish to use an alternative method in the functions.php file
<?php if( get_field('franchise_profile_url') ): ?>
Contact Franchise →
<?php endif; ?>
This is a rather complicated one, so I'm sort of expecting this to sink without a trace - but worth a go.
What I'm looking to do is have a Tags page which has a table of contents (tags list). When clicking on a tag in the table of contents, you would skip down the page to the relevant tag (using an anchor?). Here it would display the chosen tag name with its tag description and link to the tag page.
Any ideas on how I could implement this would be greatly appreciated. I've combed the Wordpress codex and Stackoverflow and not found much documentation on echoing tag lists in this way.
Thanks in advance anyone who can help!
You can use the get_tags functions to get all the tags, make a ul with them with links to their slugs(or anything unique) and then display them with something like this (slightly modified version of the codex example)
$tags = get_tags();
$html = '<div id='anchor_{$tag->slug}' class="post_tags">';
foreach ( $tags as $tag ) {
$tag_link = get_tag_link( $tag->term_id );
$html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
$html .= "{$tag->name}</a>";
}
$html .= '</div>';
echo $html;
function flx_social_sharing_buttons($content) {
// Show this on post and page only. Add filter is_home() for home page
if(is_singular()){
// Get current page URL
$shortURL = get_permalink();
// Get current page title
$shortTitle = get_the_title();`enter code here`
// Construct sharing URL without using any script
$twitterURL = 'https://twitter.com/intent/tweet?text='.$shortTitle.'&url='.$shortURL.'&via=flx';
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$shortURL;
$googleURL = 'https://plus.google.com/share?url='.$shortURL;
$tumblrURL = 'http://www.tumblr.com/share/link?url='.$shortURL;
// Add sharing button at the end of page/page content
$content .= '<div class="flx-social">';
$content .= '<a class="flx-link flx-facebook" href="'.$facebookURL.'" target="_blank"><i class="fa fa-facebook"></i></a>';
$content .= '<a class="flx-link flx-twitter" href="'. $twitterURL .'" target="_blank"><i class="fa fa-twitter"></i></a>';
$content .= '<a class="flx-link flx-googleplus" href="'.$googleURL.'" target="_blank"><i class="fa fa-google-plus"></i></a>';
$content .= '<a class="flx-link flx-tumblr" href="'.$tumblrURL.'" target="_blank"><i class="fa fa-tumblr"></i></a>';
$content .= '</div>';
return $content;
}else{
// if not post/page then don't include sharing button
return $content;
}
};
add_filter( 'the_content', 'flx_social_sharing_buttons');
i use this code to display sociAl sharing buttons below my post ,
i need to add shortcode functionality so that it appears wherever i want
how to do it pls help
You simply can do it with bellow code,
<?php echo do_shortcode('[the_content]'); ?>
just pest this code where you want social icons and u can get it on those place.
I'm not sure that I understand your question correctly, but hopefully you'll be able to use the following to address your challenge.
If I wanted to repurpose the function to render the social sharing buttons, I would start of by changed the first line to
function flx_social_sharing_buttons($content = false) {
The code should at this stage still, as expected, add the social sharing buttons after each post. To add it programmatically or within a post or page you can add the following line, creating a shortcode:
// Add the [my-social-buttons] shortcode
add_shortcode( 'my-social-buttons', 'flx_social_sharing_buttons' );
Documentation available at: https://codex.wordpress.org/Shortcode_API
Great resource for creating shortcodes and other Wordpress features:
http://generatewp.com
You can now use the shortcode in a post or page. To use it inside a php file, do the following
echo do_shortcode('[my-social-buttons]');
If you find that you'd rather now use your function programatically all that's left to do is to remove the original hook, if your social sharing buttons are now duplicated:
// Remove or comment out
// add_filter( 'the_content', 'flx_social_sharing_buttons');