#divitips Add page name to contact form

Why might this be useful? To work out which page people were on when they submitted a page.

add_filter('et_pb_module_shortcode_attributes', 'dbc_add_post_link_to_contact_form', 10, 3);

function dbc_add_post_link_to_contact_form($props, $attrs, $render_slug) {

if ($render_slug !== 'et_pb_contact_form' || !is_array($props)) { return $props; }

if (!empty($props['custom_message'])) {

$title = get_the_title();

$url = get_permalink();

$props['custom_message'] = str_replace('%%post_name%%', $title, $props['custom_message']);

$props['custom_message'] = str_replace('%%post_url%%', $url, $props['custom_message']);

$props['custom_message'] = str_replace('%%post_link%%', ''.esc_html($title).'', $props['custom_message']);

}

return $props;

}

Then you can use the following placeholders in your form message:

%%post_name%% – the title of the post / page
%%post_url%% – the URL of the post / page
%%post_link%% – a html link containing the post title and URL