WordPress.org

Ready to get started?Download WordPress

Forums

Twitter posts to Blog
[resolved] Add featured image to all tweets (5 posts)

  1. closer01
    Member
    Posted 8 months ago #

    Hi, you have great plugin. But it only add featured image when there is photo in the tweet by $media->media_url. I want to add to all tweet post featured image from external url. how i can do this, or how i can remove conditional if there is photo it adds. I want to use it like below.

    $image_url = 'http://s.wordpress.org/style/images/wp-header-logo.png'; // Define the image URL here
    $upload_dir = wp_upload_dir(); // Set upload folder
    $image_data = file_get_contents($image_url); // Get image data

    http://wordpress.org/plugins/twitter-posts-to-blog/

  2. badbreze
    Member
    Plugin Author

    Posted 8 months ago #

    hmmm disable the set thumbnail image from configuration next on your theme or custom plugin or whathever you want add an action like this:

    function dg_tw_custom_image_for_tweets($post_id) {
        $fake_tweet = (object) array(
            'entities' => (object) array(
                'media' => array(
                    0 => (object) array(
                        'media_url' => YOUR_IMAGE_URL_HERE,
                        'media_url_https' => YOUR_IMAGE_URL_HERE,
                        'type' => 'photo'
                    )
                )
            )
        );
    
        $images_list = dg_tw_insert_attachments($fake_tweet,$post_id);
        set_post_thumbnail( $post_id, end($images_list['ids']) );
    }
    
    add_action('dg_tw_after_post_published','dg_tw_custom_image_for_tweets');

    i dont know if it work, i havent tested =O

    EDIT: fixed, work for me

  3. closer01
    Member
    Posted 8 months ago #

    Thank you for your answer, i am sure its working. but i am not good with php. So which page of your plugin i need to add this code? Because i want to set feature image for all tweet posts when there is no media too.

    I added to functions.php of your plugin. but nothing changed.

    Can u explain little more ... Thank you

  4. badbreze
    Member
    Plugin Author

    Posted 8 months ago #

    hmmm ok, wait i made the code for you =)

  5. badbreze
    Member
    Plugin Author

    Posted 8 months ago #

    ok made this for you, copy the file in plugin directory, edit the variable value of $image_url with the url of the image you want to place in tweets with no images and save, next activate the plugin from wordpress backend =)

    https://dl.dropboxusercontent.com/u/103059839/twitter-posts-to-blog-image-override.php

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.