Objective
To automate posting images from my WordPress blog to Pinterest with minimal ongoing effort.
The system should:
- Continuously post images – ensuring a steady Pinterest presence without manual work.
- Include both old and new images – post to Pinterest not just images from newly published blog posts.
- Spread out posting over time – to maintain consistent engagement instead of bulk uploads.
- Use existing image data – leveraging alt text for descriptions and linking back to blog posts when making posts on Pinterest.
- Preferably, eliminate reliance on paid or overcomplicated tools
Defining the Pinterest Automation
The automation needed two key components:
- A trigger – an event that determines when images should be posted.
- An action – the actual posting of an image to Pinterest.
The action was simple: automate posting an image to Pinterest. The trigger most logically would have been a new blog post, but this had several problems:
- I didn’t want only new images to be posted—I wanted older images to be posted as well.
- I didn’t want all images from a single post to be posted at once.
- I wanted the posting schedule to be spread out as long as possible.
I had about 6,000 unique images, so I decided to post 10 images per day. This meant the automation would last for nearly two years, ensuring a steady Pinterest presence without me needing to think about it.
Since each image already had alt text (mostly generated by alttext.ai), I could safely use that as the Pinterest description.
Using Pinterest In-Built Automating Functionality
After some research, I discovered that Pinterest allows RSS feeds to create pins—no API needed. This was a game-changer because I could simply generate an RSS feed of images and let Pinterest handle the posting automatically.
Generating an RSS Feed for Pinterest
I tested several WordPress plugins to generate an RSS feed that:
- Selected 10 random images per day
- Included each image’s alt text as the description
- Provided a link to the original blog post
However, none of the plugins I found could do this without requiring a paid upgrade. Instead of paying for a plugin, I decided to write the code myself with some help from ChatGPT.
How the Custom RSS Feed Works
I created a custom script that:
- Generates an RSS feed formatted to Pinterest’s specifications.
- Selects 10 images per day and marks them in a database to ensure they don’t repeat.
- Includes each image’s alt text as the description.
- Links each image back to its original blog post.
The script runs every 24 hours, creating a fresh RSS feed of 10 new images.
Pinterest then checks this RSS feed daily and automatically posts any new images found.
Future Improvements
Currently, I have a single Pinterest board where all images are posted. Ideally, I would create separate boards for different categories and modify the RSS feed accordingly.
For example, instead of a single feed at:
I could have:
The script could then filter images based on their category, allowing for more targeted Pinterest posting.
Conclusion
By bypassing the API and leveraging RSS feeds, I was able to fully automate Pinterest posting without relying on third-party services. Now, my blog images are posted daily with zero manual work, and I have a system in place that will run for nearly two years without intervention.
This method is flexible, cost-effective, and ensures that Pinterest remains a consistent traffic source for my blog.
My Pinterest Automation Script
Here is the script that I used. In order to use it:
- Create a new file in the root of your site and name it custom-image-feed.php .
- Copy and paste the script at the end of this post and put it in this new file.
- Take note of your new RSS URL which will be at https://yourdomain.com/custom-image-feed.php
- Go to: https://www.pinterest.com/business/hub/ and login. You may have to sign up for a new business account or connect up your current Pinterest account. It should be free.
- Click on Settings
- Click on Bulk Create Pins
- Add your RSS feed
As long as there is no error, it will start posting automatically within 24 hours.
<!– Start copying the script here –>
<?php header('Content-Type: application/rss+xml; charset=UTF-8'); // Load WordPress functions require_once('wp-load.php'); echo '<?xml version="1.0" encoding="UTF-8"?>'; ?> <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"> <channel> <title>My Custom Image RSS Feed</title> <link><?php echo get_site_url(); ?></link> <description>Automatically generated RSS feed for images</description> <?php $current_date = date('Y-m-d'); $stored_feed = get_option('daily_image_feed'); // If feed for today exists, reuse it if ($stored_feed && isset($stored_feed['date']) && $stored_feed['date'] === $current_date) { $selected_images = $stored_feed['images']; } else { // Get previously used images $used_images = get_option('used_images', array()); // Query for 10 random unused images $args = array( 'posts_per_page' => 10, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'rand', 'post__not_in' => $used_images, // Exclude used images 'post_status' => 'inherit', ); $query = new WP_Query($args); $selected_images = array(); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $image_id = get_the_ID(); $image_url = wp_get_attachment_url($image_id); $image_title = get_the_title(); $image_caption = get_the_excerpt(); $post_parent = get_post(get_post_parent($image_id)); if ($image_url) { $selected_images[] = array( 'id' => $image_id, 'title' => esc_html($image_title), 'link' => esc_url(get_permalink($post_parent->ID)), 'description' => esc_html($image_caption), 'image_url' => esc_url($image_url), ); } } wp_reset_postdata(); // Store the selected images for today update_option('daily_image_feed', array('date' => $current_date, 'images' => $selected_images)); // Mark selected images as used update_option('used_images', array_merge($used_images, array_column($selected_images, 'id'))); } } // Output the stored images if (!empty($selected_images)) { foreach ($selected_images as $image) { ?> <item> <title><?php echo $image['title']; ?></title> <link><?php echo $image['link']; ?></link> <description><![CDATA[<?php echo $image['description']; ?>]]></description> <!-- Pinterest-compliant image formats --> <image> <url><?php echo $image['image_url']; ?></url> </image> <enclosure url="<?php echo $image['image_url']; ?>" type="image/jpeg" /> <media:content url="<?php echo $image['image_url']; ?>" type="image/jpeg"/> </item> <?php } } else { echo '<item><title>No images found</title><description>No images available in the media library</description></item>'; } ?> </channel> </rss><!– End copying the script here –>
Leave a Reply