Last active
July 25, 2017 09:56
-
-
Save ozthegreat/0a34ed736d7402351b35549423c16f8c to your computer and use it in GitHub Desktop.
WordPress Facebook Instant Articles - How to apply different styles to posts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Changes the Instant Article style for this post based on category. | |
* | |
* This is fired within the loop. | |
* | |
* @param string $style The default style. | |
* @return string The new style to apply. | |
*/ | |
function wpna_category_style( $style ) { | |
// If the post has any of these categories then return a custom style. | |
if ( has_category( array( 'actor', 'director' ) ) ) { | |
return 'movies'; | |
} | |
// Else return the default style. | |
return $style; | |
} | |
add_filter( 'wpna_facebook_post_get_style', 'wpna_category_style', 10, 1 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Changes the Instant Article style for this post based on tag. | |
* | |
* This is fired within the loop. | |
* | |
* @param string $style The default style. | |
* @return string The new style to apply. | |
*/ | |
function wpna_tag_style( $style ) { | |
// If the post has any of these tags then return a custom style. | |
if ( has_tag( array( 'romance', 'action', 'comedy' ) ) ) { | |
return 'movies'; | |
} | |
// Else return the default style. | |
return $style; | |
} | |
add_filter( 'wpna_facebook_post_get_style', 'wpna_tag_style', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment