Forked from webdados/excerpt-as-instant-article-subtitle.php
Created
January 11, 2017 15:42
-
-
Save mvital/5d8c3e1a398055ddba5b4d1865207d7d to your computer and use it in GitHub Desktop.
Use WordPress post excerpt as Facebook Instant Article subtitle
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 | |
/* Instant Articles (https://wordpress.org/plugins/fb-instant-articles/) - Use post excerpt as subtitle */ | |
add_filter( 'instant_articles_subtitle', 'hf_instant_articles_subtitle' ); | |
function hf_instant_articles_subtitle( $subtitle ) { | |
$excerpt = get_the_excerpt(); | |
if ( trim($excerpt)!='' ) $subtitle = trim($excerpt); | |
return $subtitle; | |
} |
For those that stumbled on here through Google, I got this working with a slight variation:
add_filter( 'instant_articles_subtitle', 'hf_instant_articles_subtitle', 10, 2 );
function hf_instant_articles_subtitle( $subtitle, $this ) {
$post_id = call_user_func( array( $this, 'get_the_id' ) );
$excerpt = get_the_excerpt( $post_id );
if ( trim( $excerpt ) != '' ) $subtitle = trim( $excerpt );
return $subtitle;
}
Thank you!
It works for me ↓
add_filter( 'instant_articles_subtitle', 'hf_instant_articles_subtitle' ); function hf_instant_articles_subtitle( $subtitle ) { $excerpt = get_the_excerpt(); if ( trim($excerpt)!='' ) $subtitle = trim($excerpt); return $subtitle; }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
subtítulos dos artigos no facebook com o excerpt
Filtro plugin https://wordpress.org/plugins/fb-instant-articles/