
Several service pages can share one Contact Form 7 definition while suggesting a different service on each page. A shortcode attribute can supply that starting value without adding a query string to the visitor’s URL. CF7 supports this through default:shortcode_attr, but adding an arbitrary attribute to the page shortcode is only part of the setup.
The attribute must also be registered through a WordPress filter. This guide uses a harmless service label to explain that contract, shows a narrow registration example, and describes how to verify the final answer. It extends our general prefill guide with the implementation needed for page-authored shortcode context.
Choose a descriptive value
Use the attribute for a suggestion such as Maintenance or Migration. Let the visitor see and correct it. Do not use this pattern as proof of account ownership, a trusted price, a permission level or an instruction to send data to an arbitrary destination. A prefilled input is still part of a visitor-controlled request.
Prefer a short list of stable service labels when the receiving team groups inquiries. Record the accepted labels and what should happen when a visitor edits one. Unknown text should reach a general review path rather than silently creating a new business rule. The suggested value helps conversation; the server must make any privileged decision independently.
Create the matching field
The official shortcode-default guide uses a field name that matches the shortcode attribute. Here the shared field is named service. In the CF7 Form tab, an illustrative definition is:
<label>Service you are asking about
[text service default:shortcode_attr]
</label>
The label remains visible after the field fills. This is an actual initial value, not placeholder text. If the page supplies no matching value, do not assume a service was chosen. Decide whether an empty optional answer is acceptable or whether your form should require a deliberate answer before submission.
Register only the intended attribute
WordPress combines known shortcode attributes with their supported defaults. Its shortcode attribute filter exposes the parsed result and the supplied attributes. CF7’s documented filter name is shortcode_atts_wpcf7. The following example accepts just the service key:
add_filter( 'shortcode_atts_wpcf7',
function ( $out, $pairs, $atts ) {
if ( isset( $atts['service'] )
&& is_string( $atts['service'] ) ) {
$out['service'] = sanitize_text_field( $atts['service'] );
}
return $out;
},
10,
3
);
Have a maintainer place reviewed PHP in the site’s established customization location, such as a small site-specific plugin or the existing snippet workflow. Do not edit CF7’s own files. This sample registers a descriptive string; it does not create a complete authorization rule or guarantee a particular lead category. Avoid copying every supplied attribute into the result because that expands the contract without a clear need.
The filter can run for multiple CF7 shortcodes. Use a distinctive field name and document its purpose so another form does not accidentally adopt the same meaning. If the site needs different rules by form, the maintainer should design and review that scope explicitly rather than assuming this general filter is already limited to one form.
Add the value on each page
Use the actual shortcode copied from your form’s admin screen, preserving its current ID. Add the matching attribute. The ID below is a placeholder for illustration:
[contact-form-7 id="123" title="Service inquiry" service="Maintenance"]
On a second page, the same form reference can use service="Migration". Put shortcode syntax in the page’s Shortcode block when using this pattern. The official CF7 block and a shortcode are different placement interfaces; adding a custom shortcode attribute is not a claim that the block exposes an equivalent field in its sidebar.
Keep the values in editorial instructions for the relevant pages. A future page editor should know that changing the visible service description may also require changing the attribute. Our block and shortcode placement guide covers references and placement checks.
Map the submitted answer into the workflow
Include [service] in the appropriate notification body if the receiving team needs it. Inspect any CRM or automation mapping independently. The shortcode provides a starting value in the browser; it does not establish a native connector or ensure that every downstream destination saves the field.
Separate the final answer from its origin. If a visitor changes Maintenance to Migration, the submitted service represents that edited answer. It cannot prove which page supplied the suggestion. Use your established page-source workflow when the original page is also important, and document how the two fields differ.
Verify the contract in staging
Use an authorized staging copy and synthetic data. Open both pages in fresh sessions. Confirm each shows its intended value, that the label remains clear on mobile, and that keyboard users can edit the answer. Then submit only to a controlled destination and compare the final notification and receiving record.
Also check the page with the attribute omitted, an empty value, and an edited answer. If the value never appears, compare the field name, the attribute name and filter activation. If it appears on the wrong page, inspect the saved page shortcode and caching behavior. Simplify to one source while diagnosing; multiple fallbacks can conceal a missing registration.
Maintain a small customization
Keep the previous snippet and affected page references in a focused change record. Recheck after CF7, theme or snippet-manager changes. A PHP syntax check is useful before activation, but it cannot replace confirming the rendered value and destination mapping.
Svetlik Analytics for Contact Form 7, our free plugin, provides submission statistics in WordPress. Use it alongside the verified setup; its trend dashboard does not validate shortcode registration or distinguish a suggested value from a visitor’s deliberate edit.
Sources
Official references checked October 15, 2026: CF7 shortcode defaults, contextual defaults, WordPress shortcode filter, and text sanitization. The sample is a configuration example, not a report of deployment or firsthand testing on your site.
