Once you get URL of the image from Instagram and you know id
of the post, you can use use the function from your question. You have to modify the code for the only if
statement in it:
if( wp_mkdir_p( $upload_dir[ 'path' ] ) ) {
$file = $upload_dir[ 'path' ] . "https://wordpress.stackexchange.com/" . $filename;
} else {
$file = $upload_dir[ 'basedir' ] . "https://wordpress.stackexchange.com/" . $filename;
}
This function will upload the image to the media library and set it as a featured image for your post. Tested!
Or, based on suggestion by @TomJNowell from his comment, use this code:
$attach_id = media_sideload_image( $image_url, $post_id, 'Instagram image', 'id' );
set_post_thumbnail( $post_id, $attach_id );
Related Posts:
- Plugin update error message
- Redirect to another page using contact form 7? [closed]
- Prevent publishing the post before setting a featured image?
- Keep one user logged for a year?
- Customizing subject in comment notification e-mails
- WP showing “warning: call_user_func_array()”, What to do?
- How to Loop Plugin Option Field Set?
- Can we completely remove the WordPress Sitemaps (WordPress 5.5)?
- Set a User as Author of all ‘New Posts’ posted
- Post source link plugin – small modification
- How to turn off email you receive when registered?
- How can i change an image’s author?
- HELP: Integrating WP with raw PHP code once published button is hit
- How to redirect Old Post URL to new Post and keep Old post Comments?
- Modifying Footnote Plugin for Descriptive Title Attributes
- I would like to use create a function in my custom plugin to tell WP to use a different header
- New Plugin: Post update pushes a copy as a revision
- Set WordPress Featured Image For All Post Slugs Matching Image File Name in Specified Directory
- bulk change of image setting “link to” to “link to: image url “
- How to get post URL in the_content filter?
- How to get subscription key or id using Woocommerce Subscriptions [closed]
- Missing argument 3 for wp_register_sidebar_widget()
- WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page
- add_query_arg not working
- Shortcode button dosent work for all posts. Work for first post only
- How to stop or remove an action being called inside a function of an extended class
- Theme my Login plugin, how to update fields
- Edit Yoast SEO breadcrumbs output [closed]
- Date calculations from 2 custom fields
- How to enable specific plugin only based around shop manager role?
- Adding a new field to the address field type in gravity forms
- Nested shortcode functions accessing variable
- All sites themes functions.php have been changed
- Customize permalink wordpress category id
- WP Query. Is there a maximum size?
- Load Javascript from Plugin in One Page Only?
- Checking the count within a foreach loop
- Why can’t I call a (member) function from within a foreach?
- Are there action hooks for comments?
- Help with WP Business Directory Manager Plugin?
- wp_dequeue_script for a Plugin
- Need to replace Currency Shortforms
- Return multiple values in a shortcode attribute
- get specific value of a array | PHP
- Plugin onclick button activate other plugin
- Api external with wordpress
- Different registration form for different roles
- Add_image_size not generating correct size
- Can you echo PHP code from a variable?
- Custom Logo Link WordPress
- How to convert Currency from USD to other IP Based currency in Php function
- how to validate input field in wordpress generated with wpform plugin
- add_rewrite_rule to load different page, without changing URL in browser
- implement custom roles in custom plugin
- WordPress Custom Hook with Class method
- How to get current cart values using WC_Shortcodes?
- Attempting to list all product categories and the price range of all products within them
- Allow a particular user to access a particular plugin?
- Share my WordPress plugin for updating how?
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- Submitting form to PHP
- Adding discount functionality to the cart
- Precheck fields when I add a new post
- front end editor creation for Restropress plug in – displaying information from a WP admin area, on a different URL
- Get Shortcode output to database for static post_content
- working code, not working – Plugin Dev
- Change custom rewrite rule when permalink is updated/changed
- Return function results within shortcode
- Configuring default woo commerce login with modal popup
- Compare Ajax Data Results
- register_activation_hook doesn’t fire at all
- Nested DIV’s across functions in PHP, do not seem to work
- My ajax request don´t work and return 0
- Populate select option with JSON file
- Every time I use wp_get_current_user() my plugin breaks
- Find all strings between an enclosing shortcode
- Create csv file in plugin
- Cannot access variables within a widget
- Posting code inside the post instead of in the template file using shortcode
- WordPress function to add text
- Saving plugin data returns “You do not have sufficient permissions to access this page.”
- Metabox Data not saving
- How to add a handler for a button in plugin?
- Can anyone tell me why I can’t edit a plugin when it is installed without having to re-install?
- Doing action based on input from options menu
- Including a PHP file via a function that is part of a plugin?
- How to disable register and reset the password from WordPress admin panel?
- Move related products after product summary? [closed]
- How to tweak a plugin without preventing it from updating
- Adminimize Plugin — Is there an alternative to limiting Editor to ‘Appearance > Widgets’ only?
- Integrate Razorpay quick payments plugin with contact form7 plugin
- Woocommerce disable checkout on specific day
- Display Video as Post Thumbnail
- Adding a script & php to functions.php
- PHP Creating a formula from mysql db values and db stored math operator
- Option value not getting updated until page refresh in WordPress
- Make plugin admin page visible to other roles
- WordPress Convert queries to slashes using function.php
- Sort posts by Date (DESC) and by ACF: active_inactive (ASC)
- WordPress Custom Page Blog Template Pagination Problem (Pagination Not Displaying)