This is a twofold question :

  1. How can I customize message that jetpack posts on facebook when my post is published (select if title or excerpt are shown)? Sometimes it posts just article title with a link, and sometimes it posts excerpt from an article and a link below it.
  2. How can I use ACF (custom fields) with Jetpack publicize? I would like to construct custom text message from custom fields to show on facebook when auto publishing.

After a lot of work and coding I found out the solution.

This is the working code that you can easily understand. Place it in your theme functions.php file or in your custom plugin.

  • With the filter 'jetpack_open_graph_tags' you can change the OpenGraph tags read by socials in order to display the link with right thumbnail and link text.
  • With the action 'publicize_save_meta' you can change the value used to build the message in socials.

All my content are read from ACF fields by get_field('field_name', id);, but there can be everything.

Happy coding!

 * OpenGraph Tags in order to display the link correctly (image, text ecc..) in Facebook
function change_jetpack_og_publicize($tags) 
    global $post;

    Content of $tags

    //Overwrite if is singular
        //ACF fields
        $tags['og:description'] = strip_tags(get_field('testo', $post->ID));
        $tags['og:image'] = get_field('immagine', $post->ID)['url'];

    return $tags;
add_filter( 'jetpack_open_graph_tags', 'change_jetpack_og_publicize' );

 * Message to display in the Facebook Post
function change_jetpack_message_publicize($submit_post, $post_id, $service_name, $connection) 
    //ACF field
    update_post_meta( $post_id, '_wpas_mess', strip_tags(get_field('testo', $post_id)));
add_action( 'publicize_save_meta', 'change_jetpack_message_publicize', 10, 4 ); 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.