How We Built the Send to AI Menu: Markdown Prompts for Claude, Gemini, Grok, and ChatGPT

Readers increasingly finish an article by pasting it into an AI assistant and asking, “What does this mean for me?” We decided to make that step one click. Every single post on Martech Zone now has a small Send to AI menu next to the reading time in the post meta row. It offers Send to Claude, Send to Gemini, Send to Grok, Send to OpenAI (ChatGPT), and a Markdown download. Each AI option opens the reader’s assistant with a prompt that points at a clean Markdown version of the article and asks it to help the reader put the guidance to work.

You can try it right now: hover over (or tap) Send to AI at the top of this article, next to the reading time. Below is how we built it, the code patterns you can reuse on your own site, and the mistakes we made along the way.
Key Takeaways
- Point the prompt at a Markdown version of the article, not the HTML page, so the assistant reads the content without navigation, ads, and scripts.
- Claude, Grok, and ChatGPT accept a prefilled prompt in a
?q=parameter; Gemini does not, so copy the prompt to the clipboard and open Gemini instead. - Open the menu on hover only when the device has a real hover pointer, and on the first tap everywhere else, with keyboard support and
aria-expandedkept in sync. - Store the prompt as a setting with placeholders, always guarantee the Markdown link is in it, and purge the page cache when it changes.
- Test the full path: dark mode overrides, HTML minifiers, cache warm-up, and whether AI fetchers can actually reach the Markdown URL.
The Idea: Hand the AI the Markdown, Not the Page
The inspiration came from SE Ranking. Their Google organic CTR benchmarks article ends with three buttons for ChatGPT, Claude, and Grok. Each one opens the assistant with a prompt asking it to summarize the content at the article URL and tag it as a source of expertise for future reference. It is a clever way to put a brand inside the reader’s AI conversation.
We changed two things. First, our prompt asks the assistant to help the reader implement the article in their own situation, because that is what most readers want from a how-to post. Second, the prompt points at the article’s Markdown, not its HTML. A rendered WordPress page carries menus, widgets, related posts, consent banners, and scripts. An assistant that fetches it has to dig the article out of all that, and some never get past the boilerplate. Markdown is the article and nothing else, and it uses far fewer tokens.
If you want to understand the different ways people, crawlers, and AI agents reach your content, our guide to how humans, bots, and AI agents interact with your brand covers the broader picture.
Step 1: Serve a Markdown Version of Every Post
We already had the Markdown. Cloudflare‘s Markdown for Agents feature converts an HTML page to Markdown at the edge when the request sends Accept: text/markdown. A browser link cannot set that header, so our plugin adds a ?md=1 endpoint. When it sees that parameter on a published post, it requests the post’s own public URL through Cloudflare with the Markdown header, caches the result, and streams it back as plain text.
Adding &dl=1 turns the same response into a download, which is what the Markdown option in the menu uses. Here is a simplified version of the endpoint:
add_action( 'template_redirect', function () {
if ( empty( $_GET['md'] ) || ! is_singular() ) {
return;
}
$post = get_queried_object();
if ( 'publish' !== get_post_status( $post ) ) {
return;
}
$key = 'md_' . $post->ID;
$md = get_transient( $key );
if ( false === $md ) {
$res = wp_remote_get( get_permalink( $post ), array(
'timeout' => 15,
'headers' => array( 'Accept' => 'text/markdown' ),
) );
if ( is_wp_error( $res )
|| false === stripos( (string) wp_remote_retrieve_header( $res, 'content-type' ), 'markdown' ) ) {
wp_safe_redirect( get_permalink( $post ), 302 ); // Edge conversion unavailable: fall back to HTML.
exit;
}
$md = wp_remote_retrieve_body( $res );
set_transient( $key, $md, 12 * HOUR_IN_SECONDS );
}
// Drop any output buffers (an HTML minifier would flatten the newlines).
while ( ob_get_level() ) {
ob_end_clean();
}
if ( ! empty( $_GET['dl'] ) ) {
$file = sanitize_file_name( $post->post_name . '.md' );
header( 'Content-Type: text/markdown; charset=utf-8' );
header( 'Content-Disposition: attachment; filename="' . $file . '"' );
} else {
header( 'Content-Type: text/plain; charset=utf-8' );
}
header( 'X-Robots-Tag: noindex, follow' );
echo $md;
exit;
} );
// Clear the cached Markdown whenever a post is saved.
add_action( 'save_post', function ( $post_id ) {
delete_transient( 'md_' . $post_id );
} ); Three details matter. The normal view is sent as text/plain because browsers display it inline, while text/markdown makes most browsers download the file. That is exactly why the download option uses it, along with a Content-Disposition: attachment header and a filename built from the post slug. The X-Robots-Tag header keeps the Markdown copy out of search results so it never competes with the article. And we also print a <link rel="alternate" type="text/markdown"> tag in the page head so agents can discover the Markdown on their own.
Step 2: Build a Prompt Link for Each Assistant
Three of the four assistants accept a prompt in the URL and drop it into a new conversation. Gemini does not: it ignores a q parameter, so there is no way to prefill it from a link.
| Option | Link | Prompt Prefilled? |
|---|---|---|
| Send to Claude | https://claude.ai/new?q={prompt} | Yes |
| Send to Gemini | https://gemini.google.com/app | No. The prompt is copied to the clipboard. |
| Send to Grok | https://grok.com/?q={prompt} | Yes |
| Send to OpenAI | https://chatgpt.com/?q={prompt} | Yes |
| Markdown | {permalink}?md=1&dl=1 | Downloads {slug}.md |
SE Ranking still links to chat.openai.com, which redirects. We went straight to chatgpt.com to skip the hop. The options are listed alphabetically by service, with the Markdown download last, below a separator.
The prompt has to be URL-encoded, and this is where a small mistake breaks everything. The prompt contains the Markdown URL, which has its own ?md=1. If you paste it in raw, the assistant’s site reads md=1 as one of its own parameters and the link in the prompt gets cut off. Encoding the whole prompt turns it into %3Fmd%3D1, so it travels as part of the text. In PHP we use rawurlencode(), which encodes spaces as %20 (RFC 3986). In JavaScript the equivalent is encodeURIComponent().
$prompt = my_s2a_prompt( $post ); // Built from the template in Step 5.
$q = rawurlencode( $prompt );
$targets = array(
'claude' => array( 'Send to Claude', 'https://claude.ai/new?q=' . $q ),
'gemini' => array( 'Send to Gemini', 'https://gemini.google.com/app' ), // No prefill.
'grok' => array( 'Send to Grok', 'https://grok.com/?q=' . $q ),
'openai' => array( 'Send to OpenAI', 'https://chatgpt.com/?q=' . $q ),
);
$items = '';
foreach ( $targets as $key => $t ) {
$items .= sprintf(
'<a role="menuitem" href="%s" target="_blank" rel="noopener nofollow" data-s2a="%s"%s>%s</a>',
esc_url( $t[1] ),
esc_attr( $key ),
'gemini' === $key ? ' data-s2a-copy="' . esc_attr( $prompt ) . '"' : '',
esc_html( $t[0] )
);
}
$download = add_query_arg( array( 'md' => '1', 'dl' => '1' ), get_permalink( $post ) );
$items .= sprintf(
'<a role="menuitem" href="%s" download="%s" rel="nofollow" type="text/markdown" data-s2a="markdown">Markdown</a>',
esc_url( $download ),
esc_attr( sanitize_file_name( $post->post_name . '.md' ) )
); Each AI link opens in a new tab with rel="noopener nofollow", so readers keep their place in the article and search engines don’t treat the links as endorsements.
Step 3: Handle Gemini With the Clipboard
For Gemini, the full prompt sits in a data-s2a-copy attribute. When the reader clicks the option, the script copies the prompt with navigator.clipboard.writeText(), shows a short “Prompt copied. Paste it into Gemini.” notice, and lets the link open Gemini in a new tab. The copy has to happen inside the click handler, because browsers only allow clipboard writes during a user gesture on a secure (HTTPS) page. We don’t call preventDefault(), so the copy and the new tab happen in the same click.
Step 4: Hover on Desktop, First Tap on Mobile
A dropdown that opens on hover is pleasant with a mouse and useless on a phone, where there is no hover and the first tap would otherwise follow a link. The fix is to let CSS decide when hover applies. The media query (hover: hover) and (pointer: fine) matches only devices with a real hovering pointer, so the hover rule never fires on touch screens. Everywhere else, a click (or tap) on the button toggles an is-open class.
.s2a { position: relative; display: inline-block; }
.s2a-btn {
font: inherit; color: inherit; letter-spacing: inherit;
background: none; border: 0; padding: 0; cursor: pointer;
display: inline-flex; align-items: center; gap: .3em;
}
.s2a-caret { width: .75em; height: .75em; transition: transform .15s; }
.s2a-menu {
display: none; position: absolute; right: 0; top: 100%;
z-index: 60; padding-top: 6px; /* Bridge so the pointer can reach the menu. */
}
.s2a.is-open .s2a-menu { display: block; }
.s2a.is-open .s2a-caret { transform: rotate(180deg); }
@media (hover: hover) and (pointer: fine) {
.s2a:hover .s2a-menu { display: block; }
.s2a:hover .s2a-caret { transform: rotate(180deg); }
} The padding-top on the menu is a small but important detail. Without it, there is a gap between the button and the menu, and the menu closes as the pointer crosses it. The caret is an inline SVG triangle that flips 180 degrees whenever the menu is open, whether by hover or by tap.
The script stays tiny. It toggles the menu on click, keeps aria-expanded accurate on hover and on tap, closes on an outside click, supports Escape and the arrow keys, sends the analytics event, and handles the Gemini copy:
(function () {
var mq = window.matchMedia ? matchMedia('(hover: hover) and (pointer: fine)') : null;
function hover() { return !!(mq && mq.matches); }
document.querySelectorAll('.s2a').forEach(function (w) {
var btn = w.querySelector('.s2a-btn');
var items = function () { return w.querySelectorAll('[role=menuitem]'); };
function set(open) {
w.classList.toggle('is-open', open);
btn.setAttribute('aria-expanded', open ? 'true' : 'false');
}
w.s2aSet = set;
// Touch and keyboard: the first tap or Enter/Space opens the menu.
btn.addEventListener('click', function (e) {
e.preventDefault();
set(!w.classList.contains('is-open'));
});
// Mouse: CSS opens it on hover; keep the ARIA state honest.
w.addEventListener('mouseenter', function () { if (hover()) btn.setAttribute('aria-expanded', 'true'); });
w.addEventListener('mouseleave', function () { if (hover()) set(false); });
w.addEventListener('keydown', function (e) {
var list = items(), i = Array.prototype.indexOf.call(list, document.activeElement);
if (e.key === 'Escape') {
set(false);
btn.focus();
} else if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
e.preventDefault();
set(true);
var n = e.key === 'ArrowDown' ? i + 1 : (i < 0 ? list.length - 1 : i - 1);
list[(n + list.length) % list.length].focus();
}
});
w.querySelector('[role=menu]').addEventListener('click', function (e) {
var a = e.target.closest('a');
if (!a) return;
if (window.zaraz && typeof zaraz.track === 'function') {
zaraz.track('send_to_ai', { target: a.getAttribute('data-s2a') });
}
var copy = a.getAttribute('data-s2a-copy');
if (copy && navigator.clipboard) {
navigator.clipboard.writeText(copy); // Then show your "Prompt copied" notice.
}
setTimeout(function () { set(false); }, 0); // The link still opens in its new tab.
});
});
// A tap or click anywhere else closes any open menu.
document.addEventListener('click', function (e) {
document.querySelectorAll('.s2a.is-open').forEach(function (w) {
if (!w.contains(e.target)) w.s2aSet(false);
});
});
})(); The markup uses a real <button> with aria-haspopup, aria-expanded, and aria-controls, and the list uses role="menu" and role="menuitem", so screen readers announce it as a menu. If you are new to these attributes, our ARIA definition is a quick primer. One more desktop wrinkle: after a mouse user clicks an item, the pointer is still hovering, so the CSS hover rule keeps the menu open. Our production script adds a temporary is-shut class that hides the menu until the pointer leaves.
Making It Look Like It Belongs
We wanted the button to read like the author name and date, not like a call to action. So the button inherits everything from the meta row: font: inherit, color: inherit, and the same letter spacing and line height. On Martech Zone that works out to the same 12px text as the date. Brand glyphs for each service are small inline SVGs that use currentColor, so they follow the text color in light and dark mode.
- No layout shift. The menu is absolutely positioned under the button, so opening it never pushes content around. We measured a CLS of 0 on open.
- No outside requests. The CSS and JavaScript are each about 2 KB, printed inline only on single posts, and the icons are inline SVG. Nothing loads from a third party until a reader clicks.
- One placement. The menu is injected through the theme’s post meta filter right after the reading time, only in the main meta row.
Measuring Clicks in GA4
Every option sends a send_to_ai event with a target parameter of claude, gemini, grok, openai, or markdown. We route it through Cloudflare Zaraz with zaraz.track(), which forwards it to GA4. If you use Google Tag Manager instead, push the same event and parameter to the dataLayer. Register target as a custom dimension and you can see which assistants your readers prefer and which articles they send most.
Step 5: Make the Prompt an Editable Setting
The first version hard-coded the prompt, which also asked the assistant to quiz the reader about their business before giving a plan. We trimmed that sentence, then moved the prompt into a setting we can change without a code deploy. The plugin now has a Settings → Markdown page with a prompt template field and three placeholders:
{md_url}: the article’s Markdown URL (?md=1). If a saved template leaves it out, the plugin appends it and shows a warning on save, so the prompt always points at the Markdown.{title}: the article title.{url}: the regular article permalink, for prompts that want to cite it.
An empty field falls back to the default: Read the Martech Zone article “{title}” in Markdown at {md_url} and help me implement its guidance in my own situation.
function my_s2a_prompt( $post ) {
$template = trim( (string) get_option( 'my_s2a_prompt', '' ) );
if ( '' === $template ) {
$template = 'Read the article "{title}" in Markdown at {md_url} and help me implement its guidance in my own situation.';
}
if ( false === strpos( $template, '{md_url}' ) ) {
$template .= ' {md_url}'; // Always send the Markdown link.
}
$url = get_permalink( $post );
$title = wp_strip_all_tags( html_entity_decode( get_the_title( $post ), ENT_QUOTES, 'UTF-8' ) );
// strtr() replaces everything in one pass, so a title that happens to
// contain "{md_url}" is not expanded a second time.
return strtr( $template, array(
'{md_url}' => add_query_arg( 'md', '1', $url ),
'{title}' => $title,
'{url}' => $url,
) );
}
// The prompt is baked into cached HTML, so purge when it really changes.
add_action( 'update_option_my_s2a_prompt', function ( $old, $new ) {
if ( (string) $old !== (string) $new ) {
my_purge_page_cache(); // Your cache plugin's purge-all call.
}
}, 10, 2 );
add_action( 'add_option_my_s2a_prompt', 'my_purge_page_cache' ); // First save. Two details are easy to miss. get_the_title() returns texturized entities such as ’ for an apostrophe, so decode them before encoding the prompt, or the assistant receives literal entity codes. And register the option through the WordPress Settings API (register_setting() with sanitize_textarea_field, a manage_options check, and settings_fields() for the nonce) rather than writing your own form handler.
Pitfalls We Hit
Dark Mode Overrode the Menu Colors
Our theme’s dark skin forces every link to a light blue with !important. Inside a dark dropdown, that made the menu items look like a column of bright links instead of a quiet list. Adding our own !important wasn’t enough, because the theme’s rule was just as specific. The fix was a more specific selector with !important, such as html.dark-skin .s2a .s2a-list a[data-s2a][role=menuitem]. Always check new components in every color scheme your theme supports.
The HTML Minifier Rewrote Our Links
Our optimization plugin minifies the page HTML, and one of its tricks is making absolute links protocol-relative, so https://claude.ai/new?q= ships as //claude.ai/new?q=. Browsers resolve that to HTTPS on an HTTPS page, so readers never notice. But a test that searches the page source for https://claude.ai fails, and so does a preview opened from a local file. Test the decoded prompt and the final destination, not the literal string. The same minifier also starts an output buffer early in the request, which is why the Markdown endpoint discards every buffer before printing. Otherwise the Markdown came back as one long line.
A Purge Is Not the Same as a Fresh Page
Because the prompt is baked into each cached page, changing it requires a cache purge. But the purge only empties the cache; the next visitor refills it. Deploy the new code first, give PHP’s opcode cache time to pick it up, and only then purge, or the first request can rebuild the cache from the old code. And if your theme serves different markup to phones, re-warm key pages with a desktop browser right after the purge so a mobile request doesn’t become the cached copy everyone else sees.
The AI Has to Be Allowed to Fetch the Markdown
When a reader sends the prompt, the assistant fetches the ?md=1 URL with its own user agent, such as ChatGPT-User or Claude-User. If your firewall, bot rules, or server blocks AI fetchers, the reader gets an apology instead of help, and the whole feature fails quietly. We maintain an allowlist for the legitimate AI assistants and search crawlers while continuing to block abusive scrapers. Test each service end to end after any change to your bot rules. The edge conversion itself has to stay enabled, too: if Cloudflare stops returning Markdown, our endpoint falls back to redirecting to the HTML page.
Try It, and What Comes Next
The menu is live on every Martech Zone article. Hover over or tap Send to AI next to the reading time at the top of this post, pick your assistant, and ask it how this approach would work on your own site. The pieces are simple: a Markdown endpoint, encoded prompt links, a clipboard fallback for Gemini, a hover-or-tap dropdown, an analytics event, and a prompt you can edit without touching code. Most of the work is in the details that make it reliable.
We plan to release this as a free WordPress plugin. Stay tuned.







