Setting custom styles in your Instant Article based on the WordPress post category
The WP Native Articles plugin allows you to pick which of your Facebook styles you’d like to use by default for your Instant Articles. This can also be overridden on a per post basis. But what if you wanted to apply a different style to every post in a certain category? Or has a particular tag? Or for each author? We haven’t built this functionality into the WordPress admin yet (let us know in the comments below if you’d like it added!) but it is fairly easy to do using the filters built into the plugin.
The filter you want is wpna_facebook_post_get_style and is in the includes/class-facebook-post.php file, line 84. When formatting a Facebook Instant Article, the default templates call this function to retrieve either the default style or the one that’s been overridden for that post. This means you can hook into it to change the value to whatever you like. Simply add any of the following code to your theme’s functions.php and change the styles as you see fit (make sure the styles are created and named correctly on your Facebook Page first otherwise it will use the default one).
Or if you want to change the style for a particular Author you can:
And finally, based on tags:
These are fairly simply examples, the filter actually runs inside the WordPress Loop so you could get as advanced as you like; serve a different style based on post date, post type, any sort of custom taxonomy, how many words are in the post…
We’re not sure how many people will actually find this useful, if it’s a much wanted featured then we’ll definitely be adding it into the admin soon, let us know below!