Support » Plugin: Tweet Images » [Plugin: Tweet Images] Tweet Image as Featured Image

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Simon Wheatley

    (@simonwheatley)

    Hi JB,

    Here’s some example code you can put in your functions.php or create as a mini-plugin:

    /**
    * Hooks the Tweet Images filter wpti_post_content to filter
    * the content which will be added to the tweet post.
    *
    * @param string $content The content (HTML)
    * @param string $message The tweet (HTML, URLs enlinkified, hashtags linked, etc)
    * @param int $post_id The post ID for the tweet post
    * @param int $attachment_id The ID of the image attachment to the tweet post
    * @return string The content
    **/
    function my_wpti_post_content( $content, $message, $post_id, $attachment_id ) {
    $content = wpautop( $message );
    update_post_meta( $post_id, '_thumbnail_id', $attachment_id );
    return $content;
    }
    add_filter( 'wpti_post_content', 'my_wpti_post_content', 10, 4 );>

    The first line sets the post content to be the text from the tweet on it’s own (rather than including an image in the HTML), and the second line sets the featured image as you requested.

    Hope this helps.

    Cheers,

    Simon

    everydream23

    (@everydream23)

    Simon,

    Thanks! Sorry it took me a few days to respond! I have been under the weather and finally got to creating the mini-plugin. Works perfectly after I figured out some php.

    You should release that as an add-on. If not I can put it on the repository if you want.

    Just let me know.

    Thanks again for helping out. This is perfect.

    JB

    Simon,

    Been racking my brain for a couple hours and now fully understanding I need to just bite the bullet and learn php instead of hacking away like I do.

    Just looking to add back in the image to the post while keeping the image as featured as well.

    Any help would be appreciated.

    Thanks,

    JB

    Plugin Author Simon Wheatley

    (@simonwheatley)

    You need to prepend or append the image to the content. I’ve tweaked the above code but not tested it, so use at your own risk…

    /**
    * Hooks the Tweet Images filter wpti_post_content to filter
    * the content which will be added to the tweet post.
    *
    * @param string $content The content (HTML)
    * @param string $message The tweet (HTML, URLs enlinkified, hashtags linked, etc)
    * @param int $post_id The post ID for the tweet post
    * @param int $attachment_id The ID of the image attachment to the tweet post
    * @return string The content
    **/
    function my_wpti_post_content( $content, $message, $post_id, $attachment_id ) {
    update_post_meta( $post_id, '_thumbnail_id', $attachment_id );
    $img = '<div class="featured-image-wrapper">' . get_the_post_thumbnail( $post_id, 'medium' ) . '</div>';
    $content = wpautop( $img . $message );
    return $content;
    }
    add_filter( 'wpti_post_content', 'my_wpti_post_content', 10, 4 );

    You can change the order of $img and $message in the line which reads $content = wpautop( $img . $message );, you can change the wrapping HTML elements in the line above, and you’ll probably need to use CSS to style the result.

    Hope this helps.

    S

    I am wanting this very thing ..I have enabled the first plugin you have above and it seems to be working. However, I believe the theme I am using does not pull the image file from the place this plugin is adding it. My theme requires a URL to the image file be provided on the edit post page.

    Is there a way for me to have this plugin supply this field with the required path?

    Thank you,

    Plugin Author Simon Wheatley

    (@simonwheatley)

    @wrx2104 – this would be possible using the wpti_published_post action, I’ve just pushed live an upgrade to the plugin which passes $attachment_id as the second parameter on the action (it was already passing the $post_id). You would need to ascertain the custom field (post meta) location that your theme is storing the image URL in and write a mini-plugin or theme function in functions.php to populate it. I appreciate this is a bit technical, but hope you can work it out or find someone to help you with your aim! Good luck!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Tweet Images] Tweet Image as Featured Image’ is closed to new replies.