Skip to content

Quick Tutorial: Pushing Content from Google Sheets to WordPress

Welcome back! Today we’re going to learn how to automate the process of pushing content from Google Sheets to WordPress. We will accomplish this using Google Apps Script and Cloudflare Workers.

Prepare your Google Sheets data: For this lesson, we’ll assume that you have a Google Sheet with four columns: Title, Content, Category, and Tags. Each row represents a separate article, with the title in column A, Title B, Content C, Category D, Tags

Write a Google Apps Script: Open Google Apps Script from your Google Sheets (Extensions > Apps Script). Write a script that will loop through categories 2345 in the sheet, extracting the A, Title B, Content C, Category D, Tags for each article.

Here is a simplified version of what your Google Apps Script might look like:

function sendToWordpress() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var data = sheet.getDataRange().getValues();

  for (var i = 0; i < data.length; i++) {
    var column = data[i];
    var email = ""; // Replace this with your unique WordPress email
    var title = column[2]; // Get the title from the third column
    var content = column[3]; // Get the content from the fourth column
    var category = column[4]; // Get the category from the fifth column
    var tags = column[5]; // Get the tags from the sixth column

    // Constructing the body of the email
    var body = "[status draft]n" + "[tags " + tags + "]n" + "[category " + category + "]n" + content;

    // Only send an email if all the fields are not empty
    if (title && content && category && tags) {
        to: email,
        subject: title, // Using the title as the subject of the email
        body: body

This script will loop through each row in your Google Sheet, extract the title, content, category, and tags, and email this to your WordPress site. Each email will create a new post on your site in draft status, allowing you to review and publish it manually.

Please note, it’s necessary to have the email-to-post feature enabled on your WordPress site for this script to work. Also, remember to replace the email address in the script with the secret email address generated by WordPress for email posting.

That’s it! You’ve now set up an automated system to push content from Google Sheets to your WordPress site. In the next lesson, we’ll explore how to generate content automatically using AI. Stay tuned!

Remember, you can always modify the script to suit your needs. For example, you might want to add a condition to only send emails for rows that haven’t been sent yet, or you might want to add more information to your posts.

Leave a Reply

Your email address will not be published. Required fields are marked *