Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Use WordPress post body as title for Jetpack Publicize
Plugin Name: chmac Jetpack Publicize Custom Message
Plugin URI:
Description: For posts with no title, set the Jetpack Publicize message to the post body.
Version: 0.1
Author: Callum Macdonald
Author URI:
function chmac_publicize_save_meta($should_publicize, $post_id, $service_name) {
// We only care about twitter, so unless we're publishing to twitter now, do nothing
if ($should_publicize && $service_name == 'twitter') {
// Get the existing custom message for this post
$existing_message = get_post_meta($post_id, '_wpas_mess', true);
// If a message has been set, there's nothing to do, return now
if (!empty($existing_message)) {
// Get the post
$post = get_post($post_id);
// If the post title is empty, then we want to set a custom message
if (empty($post->post_title)) {
// Generate the custom message by grabbing 240 chars of the post and stripping all tags
$custom_message = wp_strip_all_tags( substr($post->post_content, 0, 240) . '...' );
// Write the new custom message
$res = update_post_meta( $post->ID, '_wpas_mess', $custom_message );
add_action('publicize_save_meta', 'chmac_publicize_save_meta', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment