WordPress

Automating Scheduled Posts in WordPress to Buffer Social Media Profiles

Buffer: A Smarter Way to Share on Social Media

WordPress to Buffer app plugins just don't cut it. Get fine-tuned control over your sharing text and images when queuing posts on Buffer.

My favorite app for pushing new posts to social media is still Buffer, because it lets you manage all your outgoing content in one central location, and schedules each post to be published in a queue that shares your posts to social platforms at a time that’s best for each platform—where “best” means when the platform is most heavily trafficked.

This way, I can schedule or publish posts at whatever time, and later get them promoted on my social platforms at the optimal time. The only problem is bridging the gap between WordPress and Buffer.

There are lots of WordPress plugins that purport to do the job, but all of them fall short of features in one way or another. So I decided to write some code for WordPress that can post to Buffer plugin-free. To be clear, this is what we want to accomplish:

  • Whenever a scheduled post is published or whenever a post is published, we want it to be loaded into the Buffer queue, on all our social accounts connected to Buffer;
  • We want to be set some default sharing meta, but we also want to be able to override that meta on a per-post basis;
  • Posts that have already been sent out to Buffer shouldn’t get re-Buffered if they’ve already been sent, and we should be able to opt-out posts manually if we want.

You’ll need two things to get started: Advanced Custom Fields to build the Dashboard interface, and a single PHP file, the bufferapp-php library, from thewebguy.

Creating Buffer Settings

First we’ll want to create a panel in the Edit Screen that lets you specify specific sharing information and lock the post from being sent to Buffer manually:

With ACF, make three fields in a Buffer Settings field group:

  • Text type called “Hash Tags” with a field name of hash_tags,
  • Text type called “Share Description” with a field name of buffer_desc
  • True / False type called “Lock Post” with a field name of buffer_lock_post

And assign this field group to your default Posts post type. I changed the Position setting to “Side” so it fits in the right rail on the edit screen like above.

Send to Buffer when Publishing Scheduled Posts

Next, we need to load the bufferapp-php library, and start a session. I put the bufferapp.php in my /includes/bufferapp/ folder like so in my functions.php file:

Finally, we need to trigger the logic that sends a scheduled post to Buffer. We’ll use the publish_future_post and draft_to_publish hooks to trigger our logic:

You’ll notice throughout that you’ll need to enter a few pieces of information from Buffer in the code above. First, you can find each social media account’s profile ID in the address bar when you’re editing their queues:

Second, you need to enter replace BUFFER_CLIENT_ID and BUFFER_CLIENT_SECRET with your own tokens. To get these, you need to create an app for Buffer. You’ll also need an access token. Normally, when you interact with the Buffer API, you need to authenticate with the API first via a callback URL to get the access token. However, after you register an app with Buffer, you’ll be given the client secret, client ID, and access token. Inside the bufferapp-php library, you need to supply the access token in lieu of the code that would ordinarily retrieve it from an authenticated session:

Voila! Now when you publish posts, or when posts that are scheduled get published, WordPress will automatically send them over to Buffer in all your social queues.

You should see that the following sharing fields match up like so:

  • The post’s sharing title is the post title.
  • The post’s sharing description is the post’s excerpt + a short link to your post. In the case of LinkedIn and Twitter, hash tags are included.
  • If you’ve assigned a featured image to the post, that too will get sent along as the sharing image.
  • And finally, you can override the hash tags and sharing text by entering copy into the fields we set up with ACF in the post itself.

Have fun.


Also in WordPress


Post a Comment

Your Two Cents

Reply

Your Comments

0 Replies & Counting

There are no comments yet.