WP Webhooks / Automations / New WordPress post to LinkedIn, X and Facebook

New WordPress post to LinkedIn, X and Facebook

Every time you publish a WordPress post, this webhook sends it to one n8n webhook, which fans it out to LinkedIn, X (Twitter) and Facebook — three networks from one delivery, no per-network plugin and no Zapier task cost.

Why it goes through n8n

None of the three social APIs accept a plain API-key POST — LinkedIn, X and Facebook all require OAuth on your app's behalf, and an OAuth dance is not something a webhook can perform. n8n holds those connections, so WordPress only ever talks to one URL.

That URL is the only thing you maintain. Add Mastodon or Bluesky later and nothing changes in WordPress.

What you need first

  1. In n8n, add a Webhook node — method POST, path of your choosing — and copy its production URL.
  2. Wire a LinkedIn, an X and a Facebook Pages node after it, connecting each account inside n8n.
  3. Protect the node with header auth, and store that token in the Credentials Vault. The import asks you for it; it is never part of a shared build.

What gets sent

{
  "title": "Hello world",
  "summary": "A short excerpt.",
  "url": "https://example.com/hello-world/",
  "image_url": "https://example.com/wp-content/uploads/2026/08/hero.jpg"
}

publish_post hands over the post ID and the WP_Post object, so title and summary map straight across. The permalink and the featured image are not in that payload, so a pre-dispatch Code Glue snippet resolves them with get_permalink() and get_the_post_thumbnail_url(), falling back to get_the_excerpt() when the excerpt is empty. Nothing else travels — unmapped fields are dropped, so the rest of the post object stays in WordPress.

It only fires on a real publish

publish_post is not a "new post" hook. WordPress fires it on every save where the status is publish, so editing a live article would announce it a second time. A condition on the old status — args.2 must not equal publish — keeps this to genuine first publications.

If a delivery fails

Delivery is asynchronous, so publishing a post never waits on n8n. A failed POST is retried 5 times — 1m, 2m, 4m, 8m — and every attempt is kept in the delivery log with the full request and response. If n8n was down for the whole ladder, hit Replay once it's back and the post goes out without republishing it.

A 200 from the webhook node only means n8n accepted the payload. Check n8n's own execution list to confirm all three social nodes succeeded.

/ The conversation

This build was not assembled by hand. Its author described what they wanted in Build with AI, and the agent read the site, planned the work and applied it. This is that conversation.

model gemini-flash-latest via hosted AI credits
Author

When new post is published lets fan out LinkedIn, X and Facebook posts. This will be done via n8n https://n8n.flowsystems.pl/webhook/30f81536-58e9-4e1d-95ab-38c63e948215 We need to send title, url, excerpt named as summary and featured image url as image_url

Build with AI

Checking the captured payload for post publishing to map title, URL, excerpt, and featured image correctly...

Build with AI

I will set up an integration to trigger your n8n workflow whenever a WordPress post is published. Here is the plan:

  1. Create Webhook: Disabled webhook pointing to your n8n URL for publish_post events.
  2. Field Mapping: Map args.1.ID to post_id, post_title to title, and post_excerpt to summary.
  3. Code Glue Snippet: Use a pre-dispatch PHP snippet to resolve url (permalink) and image_url (featured image) using standard WordPress functions, with a fallback for summary if empty.
  4. Preview & Assign: Test the snippet against captured payload and attach it to the webhook.
  5. Test Dispatch: Send a live test delivery to verify n8n accepts the payload.
  6. Enable Webhook: Turn on the integration so future published posts automatically dispatch.
Sent by the panel — Fix it

Step step_6 (test_dispatch) did not succeed: The endpoint rejected the test delivery with 403 — it needs authentication. Attach a credential to the webhook, then retry. The endpoint responded: Authorization data is wrong! Fix the build so this passes — adjust the field mapping or the pre-dispatch Code Glue snippet as needed — then test again before enabling.

Build with AI

Checking stored credentials to see if an auth header or token for n8n is already available...

Build with AI

The test dispatch was rejected by n8n with HTTP 403. I will attach your stored n8n automation credential (#11) to Webhook #31, send another test dispatch, and enable the webhook once verified.

Published by the author on purpose. Tool output and raw payloads never travel with a shared build, and secrets never leave the site they were created on.

/ Abilities used (9)

  1. create_webhook Create disabled webhook for publish_post pointing to n8n
  2. set_mapping Map post ID, title, and excerpt for n8n payload
  3. create_snippet Create PHP snippet to inject URL, featured image URL, and summary
  4. preview_snippet Preview the payload transformation with the Code Glue snippet
  5. assign_snippet Attach the pre-dispatch snippet to the webhook
  6. test_dispatch Send test delivery to n8n webhook failed
  7. assign_credential Attach stored n8n credential (#11) to Webhook #31
  8. test_dispatch Retry test delivery with authentication header
  9. enable_webhook Enable Webhook #31 to go live

Each of these is a real ability the agent can call — see the docs for what each one does.

/ What runs

Social Media Fan-out via n8n
WordPress fires
publish_post
Only when
1 condition matches
Field mapping
3 fields mapped
Code Glue
Social Media Payload Enrichment (Permalink & Featured Image) before sending
Queued, then sent
POST https://n8n.flowsystems.pl/webhook/30f81536-58e9-4e1d-95ab-38c63e948215 with your credential

Every attempt is retried on its own schedule and written to the delivery log.

WordPress fires the action publish_post, if the conditions below match, the payload is mapped and sent as POST to n8n.flowsystems.pl. The delivery is queued and sent in the background, so the visitor never waits. Along the way a Code Glue snippet shapes the payload first and authentication comes from a credential you supply on import.

/ How it is configured

Social Media Fan-out via n8n
publish_post

/ Only when

  • args.2 does not equal publish
  • ↳ otherwise the delivery is skipped, and logged as skipped

/ Field mapping

args.1.ID post_idas number
args.1.post_title title
args.1.post_excerpt summary

/ Code Glue

before sending — Social Media Payload Enrichment (Permalink & Featured Image)
$postId = $payload['post_id'] ?? null;
if ($postId) {
    $payload['url'] = get_permalink($postId) ?: '';
    $imageUrl = get_the_post_thumbnail_url($postId, 'full');
    $payload['image_url'] = $imageUrl ?: '';
    if (empty($payload['summary'])) {
        $payload['summary'] = get_the_excerpt($postId) ?: '';
    }
}
unset($payload['post_id']);
return $payload;

Read any snippet before you import it — Code Glue runs PHP on your site.

/ Authentication

This build authenticates with a credential you supply on import. The shared file carries the name and type only — never the secret.

  • n8n automation — bearer

/ Use this build

Download the file, then in WordPress open Webhook Actions → Webhooks → Import and drop it in. Anything needing authentication asks you to pick or create a credential as it imports — see Import & Export for what travels with a build and what does not.

A like sends 20 AI credits to whoever published this.

/ Published by

Mateusz

/ Questions

Do I need the Pro plugin for this build? +
Yes. This build attaches Code Glue snippets, which are a Pro feature. Everything else in it — the webhook, its triggers, the field mapping and the conditions — works on the free plugin.
How do I use it on my own site? +
Download the JSON, then in WordPress open Webhook Actions → Webhooks → Import and drop the file in. Anything that needs authentication asks you to pick or create a credential during the import — secrets are never part of a shared build.
Does the build contain the author's API keys? +
No. Export carries credential metadata only — the name, the type and a masked hint — never the secret itself. The Credentials Vault is write-only over the API by design.
Publish

Publish your automation and get 50 AI credits,
+20 for each like.

$ wp plugin install flowsystems-webhook-actions --activate