Automating Blog-to-LinkedIn Carousel Generation in n8n via WordPress REST API and Gotenberg

Repurposing long-form editorial content into visual carousels often slows down publishing pipelines. Manually copy-pasting headings and summary text into design software for every piece of content introduces unnecessary friction. Automating this layout transformation via n8n and a self-hosted engine allows teams to process incoming posts programmatically as soon as they hit WordPress.

By parsing structural heading nodes directly from the WordPress REST API and formatting those payloads into HTML/CSS slide layouts, an automated workflow can stream dynamic markup to a containerized Gotenberg instance. Gotenberg renders the dynamic HTML string into a multi-page PDF document optimized for LinkedIn’s native document uploader.

Here is the exact architectural blueprint, data model, and API configuration required to execute this pipeline end-to-end.


Step 1: Querying Raw Post Payload from WordPress

To begin the workflow, set up a WordPress trigger or standard HTTP Request node in n8n to query published posts.

When requesting post content from the core API endpoint (/wp/v2/posts), default parameters return fully rendered HTML inside content.rendered. Query parameters should isolate specific fields to keep JSON payloads small.

GET /wp/v2/posts?status=publish&per_page=1&_fields=id,title,content,slug
Host: your-wordpress-domain.com
Authorization: Bearer YOUR_APPLICATION_PASSWORD

Using _fields=id,title,content,slug reduces response overhead while fetching the essential raw string required for DOM parsing downstream.


Step 2: Extracting Structural Heading Nodes in n8n

Once the HTML string arrives in n8n, pass items[0].json.content.rendered into a Code node running JavaScript to parse structural nodes (<h2> headings and their following <p> text blocks) into discrete slide objects.

const cheerio = require('cheerio');

const htmlString = $input.first().json.content.rendered;
const postTitle = $input.first().json.title.rendered;
const $ = cheerio.load(htmlString);

const slides = [];

// Push Cover Slide
slides.push({
  slideIndex: 1,
  type: 'cover',
  title: postTitle,
  body: 'Key insights extracted from recent publication.'
});

// Extract section headers and immediately following paragraph text
$('h2').each((index, element) => {
  const headingText = $(element).text().trim();
  const nextParaText = $(element).next('p').text().trim();

  if (headingText) {
    slides.push({
      slideIndex: slides.length + 1,
      type: 'content',
      title: headingText,
      body: nextParaText || ''
    });
  }
});

// Push CTA Slide
slides.push({
  slideIndex: slides.length + 1,
  type: 'cta',
  title: 'Read the full guide',
  body: 'Visit our site to explore the complete article and workflow details.'
});

return [{ json: { slides, totalSlides: slides.length } }];

This node outputs an array of structured JSON objects. Each element represents an individual slide containing explicit title and body fields.


Step 3: Compiling HTML/CSS Template Strings

With structural array nodes mapped out, the next step generates a unified HTML document where each slide occupies a fixed square aspect ratio. Using CSS page-break-after: always; ensures that Chromium inside Gotenberg splits each container into a distinct PDF page.

Insert another Code node in n8n to map over json.slides and assemble the complete HTML document string:

```javascript const slides = $input.first().json.slides;

const slideElementsHtml = slides.map((slide) => { return <div class="slide ${slide.type}"> <div class="slide-content"> <span class="slide-number">${slide.slideIndex}</span> <h2 class="slide-title">${slide.title}</h2> <p class="slide-body">${slide.body}</p> </div> </div>; }).join(‘’);

const fullHtmlString = `<!DOCTYPE html>

${slideElementsHtml} --- *This article was generated with the help of AI.*
This post was generated by Omniposter AI. Start your free trial.