WordPress

Ask your agent to find the native WordPress button, link, or menu control on the front end. It can mark the control for a goal while keeping the block editable and its action unchanged. You can also compare wording inside the same block.

Mark an existing button

If reaching a destination is the result you care about, reuse a page goal for that destination. To count the activation itself, use a named interaction such as open-booking. Enter open-booking as the event name, not a CSS selector. Keep your existing Version Compare script.

  1. In the block editor, select the individual Button block, not the enclosing Buttons block.
  2. In Advanced, set HTML anchor to vc-booking (without #). If the block already has an anchor that other links use, keep it and use that value in the example. Additional CSS class(es) can also give you a stable hook.
  3. Inspect the front-end HTML. WordPress puts the hook on the block wrapper in its standard Button markup. Put the goal attribute on the link or button inside it.

For the standard linked Button block, put this block render filter in your child theme's functions.php or a site plugin. It uses WP_HTML_Tag_Processor (WordPress 6.2 or later) and leaves the saved block alone.

add_filter( 'render_block_core/button', function ( $html ) {
    $tags = new WP_HTML_Tag_Processor( $html );
    if ( $tags->next_tag( 'DIV' ) && 'vc-booking' === $tags->get_attribute( 'id' )
        && $tags->next_tag( array( 'tag_name' => 'A', 'class_name' => 'wp-block-button__link' ) )
        && $tags->get_attribute( 'href' ) ) {
        $tags->set_attribute( 'data-vc-goal', 'open-booking' );
    }
    return $tags->get_updated_html();
} );

If the block emits a real <button>, change A to BUTTON and remove the href check. If you own a PHP template that renders the control, add data-vc-goal directly to its native tag instead.

Mark navigation or a generated control

  • For a classic menu rendered by wp_nav_menu(), use nav_menu_link_attributes. Match the menu's theme location and the menu item ID. Set $atts['data-vc-goal'] on that item and return the other attributes unchanged.
  • For a Navigation block, set Additional CSS class(es) to vc-primary-nav on the intended block in the Site Editor. For the built-in mobile opener, verify nav.vc-primary-nav button.wp-block-navigation__responsive-container-open in the front end. Use the render_block_core/navigation filter scoped to that block to set data-vc-goal="open-menu" on the opener. Configure open-menu as its own interaction goal.
  • If a plugin generates the control in the browser, use the in-place recipe with the selector for that actual control. Enqueue the code as a theme or plugin asset with wp_enqueue_scripts. If the plugin replaces the control, reapply the attribute after it renders. Leave the native click and keyboard handlers alone.

Keep theme and plugin changes with an authorised maintainer. A post editor may not have theme access, and WordPress can strip scripts from saved content. Do not grant unfiltered_html to work around that restriction.

Compare the wording

Keep the original wording in the native block and store the alternative in a separate editable plain-text field. In the block's render filter or owned template, follow the wording recipe: put data-vc on the existing heading or label container and render a direct child span for each wording. Mark both spans with data-vc-version, and add hidden to the alternative. Use esc_html() for plain text.

For a plain Button block above, the label container is #vc-booking > .wp-block-button__link. Leave the link, its destination, and its theme classes in place. If the control contains an icon or formatted text, work in its existing label-only element or adapt its renderer. Do not replace its contents with plain text. Put wording visible on load in the initial HTML. Keep data-vc-goal on the control if you also want to count its activation.

Preview and publish

  1. Open a post or page preview in a new tab. In a recognised preview, try each wording in Show versions. Inspect the real link or button and use the mouse and keyboard to activate it. Look for Version Compare preview: not recorded and the exact event name in the console.
  2. For ordinary pages, use test mode with data-vc-test on the hosted script. After the owner approves publishing, check the page while signed out. Check mobile menu controls at mobile widths, and confirm the focus, styles, and destination still work. Leave test mode on every page until the owner separately approves removing the attribute. Reload after removal.