WordPress.org

Ready to get started?Download WordPress

Forums

Tweet Images
Tweet Image as Featured Image (7 posts)

  1. everydream23
    Member
    Posted 2 years ago #

    Just wondering how I make the image I tweet be marked as a featured image as well?

    Any chance of this happening? Don't know much about PHP at the moment.

    Thanks!

    JB

    http://wordpress.org/extend/plugins/tweet-images/

  2. Simon Wheatley
    Code for the People
    Plugin Author

    Posted 2 years ago #

    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

  3. everydream23
    Member
    Posted 2 years ago #

    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

  4. everydream23
    Member
    Posted 2 years ago #

    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

  5. Simon Wheatley
    Code for the People
    Plugin Author

    Posted 2 years ago #

    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

  6. wrx2104
    Member
    Posted 1 year ago #

    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,

  7. Simon Wheatley
    Code for the People
    Plugin Author

    Posted 1 year ago #

    @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!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic