Say you want to add your Instagram images and captions to your WordPress but you want the new photo posts to be natively added to a custom post type. Reasons for this could be that you want to feature certain posts under a certain hashtag. You could just want the ability to store your social media content on your site so you can categorize them in a way you cannot on Instagram. This could be to showcase your fan posts on your website.
Now let’s think bigger. There are a lot of integrations you can setup from different other platforms to your WordPress such as these checked below using IFTTT:
No matter the reason, there are many ways to go about it but I will be sharing a way that has worked here at The African Boss. We use a three steps process:
- setting up the custom post type
- setting up the social media to WordPress integration or any of the available integrations via IFTTT
- using your WordPress
functions.php
file to move the incoming automated posts to the appropriate custom post type – a solution by Bibhas posted here
Setting up a custom post type for your social media content
Depending on what social media you would like to move to WordPress, you usually need only 2 fields to fill out. For example, Instagram feed outputs an image/video with a caption while Instagram story outputs an image/video only and if you were to repost your Instagram feed post through “Add a New Post” on your WordPress then you might encounter fields like title, excerpt, featured image, tags, categories, etc that you do not need.
Custom post types allow you to create a post type with specific fields. When it comes to your social media posts, your post type only needs two fields: media that could be image/video, and text caption.
My favorite way of creating custom post types uses the following plugins:
For a detailed custom post type creation and setup, check out this article by WPbeginner.
Setting up the social media to WordPress integration via IFTTT
IFTTT is a platform that allows you to integrate two different platforms that are usually not connected. For example, if you want your social media posts on Instagram to automatically appear on your WordPress, you can use this IFTTT integration that will do that. Or if you want to sync your new Instagram posts to a Pinterest board, you can use this IFTTT integration that will do that. And there are many more integrations on IFTTT.
If you need to automatically post your social media posts to your website using this IFTTT integration, you will need to allow IFTTT access to your Instagram, then fill out the following form:
Once you have connected these two platforms with an IFTTT integration, you could just end here. And your social media posts will be automatically shared to your website in the posts area.
Moving incoming social media posts to the appropriate custom post type
If you would like for your social media posts to be in the same custom post type like here, then you will need to take a few extra steps. The following is a solution by Bibhas posted here.
As the only way ifttt.com can post to WordPress, is using the XML-RPC API, you can make use of the filter wp_insert_post_data
.
Here is a hack that works. You add the code below to your functions.php
file. And when editing your theme files, it is advised to use a child theme because changes made to a child theme functions.php
will not be reversed after a theme upgrade as they would if changes were directly made to the parent theme.
// This function detects a XML-RPC request and modifies it before posting
function redirect_xmlrpc_to_custom_post_type ($data, $postarr) {
if (defined('XMLRPC_REQUEST') || defined('APP_REQUEST')) {
$data['post_type'] = 'socialposts'; // sets the request post type to custom post type instead of the default 'Post'.
return $data;
}
return $data;
}
// Add the filter
add_filter('wp_insert_post_data', 'redirect_xmlrpc_to_custom_post_type', 99, 2);
Remember, this filter will detect any insert post request via the XML-RPC API and insert them to socialposts
custom post type. That means that if you submit your posts via email or via the WordPress mobile app, they will all be redirected to the specified custom post type such as socialposts
in this case.
I hope that you will use this knowledge to start connecting your site to different platforms and redirecting the incoming content to specific post types. To see this in action, check out our social media custom post type here.