Hi Frank,
After some testing it appears that the yikes_mc_get_form_data
filter isn’t properly altering the fields before being sent to MailChimp.
I will need to take a look at what the issue may be, and make some alterations for future releases.
You can still achieve this by creating a hidden field over on MailChimp, and then using the provided yks_mc_before_all_forms
hook to add some CSS to hide the hidden field. Something like this:
/**
* This example will hide the mmerge1 field and label
*/
function custom_before_all_forms_action() {
?>
<style>
label[for="0-adf9331235-mmerge1"], label[for="0-adf9331235-mmerge1"]+input {
display: none;
}
</style>
<?php
}
add_action( 'yks_mc_before_all_forms' , 'custom_before_all_forms_action' );
After you have your field set up and hidden, you can use the same hook to write a little jQuery to populate the input field based on the current page or post. Something like this should point you in the right direction:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery( '#0-adf9331235-mmerge1' ).val('<?php echo $page_title; ?>');
});
</script>
The entire function would then go into your functions.php file, and would look similar to:
/**
* This example will hide the mmerge1 field and label
* and populate it with the current page title
*/
function custom_before_all_forms_action() {
global $post;
$page_title = $post->post_title;
echo $page_title;
?>
<style>
label[for="0-adf9331235-mmerge1"], label[for="0-adf9331235-mmerge1"]+input {
display: none;
}
</style>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery( '#0-adf9331235-mmerge1' ).val('<?php echo $page_title; ?>');
});
</script>
<?php
}
add_action( 'yks_mc_before_all_forms' , 'custom_before_all_forms_action' );
If you wanted to get even more specific you could specify the page URL
in the field as well with a function similar to:
/**
* This example will hide the mmerge1 field and label
* and populate it with the current page URL
*/
function custom_before_all_forms_action() {
$page_url = (isset($_SERVER['HTTPS']) == 'on' ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
?>
<style>
label[for="0-adf9331235-mmerge1"], label[for="0-adf9331235-mmerge1"]+input {
display: none;
}
</style>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery( '#0-adf9331235-mmerge1' ).val('<?php echo $page_url; ?>');
});
</script>
<?php
}
add_action( 'yks_mc_before_all_forms' , 'custom_before_all_forms_action' );
You’ll want to adjust the mmerge1 name and the form ID to suit the needs of your form. You can find the name of that merge field inside of the manage lists page or over on MailChimp.com.
You can also use the above function to target specific forms, instead of on all forms. And keep in mind you can alter the above function to populate the field with all sorts of data (username, current page ID, page title, page URL etc.)
Hopefully that helps answer your question!
Evan