Closed mattpramschufer closed 8 months ago
Just seeing if you had any chance to review this yet.
Hey @mattpramschufer -
You probably want to filter both apple_news_author_byline_link and apple_news_article_metadata.
The Intro component (see below) would be a great place to add the subtitle. Alternately, you could filter the title component and add a subtitle within it, or you could filter the entire article's JSON and add it wherever you like.
"Intro" comes from the excerpt. You can filter the intro component JSON using apple_news_intro_json and set it to whatever you like.
Thanks @kevinfodness I was able to get the authors all fixed up, but for the subtitle, I am not able to update the intro. It looks like it is not even included in my article json. I have
"meta_component_order": [
"cover",
"slug",
"title",
"intro",
"author",
"date"
],
In my theme, but when I add in the filter apple_news_intro_json
it never gets ran. I also see it doesn't pass the post_id, so there wouldn't be any way for me to get subtitle from a custom field without the post_id. Any ideas?
Okay I figured it out. Not sure if this is the best way but it works!
add_filter( 'apple_news_generate_json', 'update_apple_news_json', 10, 2 );
function update_apple_news_json( $json, $post_id ) {
$subtitle = get_field( 'subtitle', $post_id );
$authors = do_shortcode( '[molongui_byline pid=' . $post_id . ' before="By " linked=no]' );
$intro_json = [
"role" => "intro",
"text" => $subtitle,
"format" => "html",
"textStyle" => [
"fontName" => 'Baskerville',
"fontSize" => 22,
"lineHeight" => 26,
"textColor" => "#333333",
"fontWeight" => 300,
"textAlignment" => "left",
],
"layout" => [
"margin" => [
"top" => 10,
"bottom" => 10,
],
],
];
array_splice( $json['components'][1]['components'], 1, 0, [ $intro_json ] );
$json['components'][1]['components'][2]['text'] = $authors;
return $json;
}
Thank you so much for all of your support. If there is a better way to do this please let me know, but I'm going to close this issue now since I have it all working.
Filtering the final article JSON is the most direct and reliable method of getting what you want in there, so yes, that's a good solution. It's possible that the intro component was bailing out before the filter was run because the excerpt wasn't set, so I think you've ended up in a good place.
Description
I have been scouring the documentation and code, and I can not figure out how to do the following.
1.) How to filter the authors, not just the byline. Use Case: We use Mongoli Authors instead of CoAuthors and I need to be able to inject the shortcode
[molongui_byline]
instead of the current authors. Is that possible?2.) We have a custom field for a Subtitle in wordpress, I didn't see anything related to a subtitle. Is there a way to add a secondary heading below the title?
3.) Is there a filter for what content we can put into "Intro"?
Thank you in advance!