Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mvital/5d8c3e1a398055ddba5b4d1865207d7d to your computer and use it in GitHub Desktop.
Save mvital/5d8c3e1a398055ddba5b4d1865207d7d to your computer and use it in GitHub Desktop.
Use WordPress post excerpt as Facebook Instant Article subtitle
<?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;
}
@mvital
Copy link
Author

mvital commented Jan 11, 2017

subtítulos dos artigos no facebook com o excerpt
Filtro plugin https://wordpress.org/plugins/fb-instant-articles/

@ErnieAtLYD
Copy link

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;
}

@shifke
Copy link

shifke commented Aug 19, 2019

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