You cannot insert remote file in this manner.
<?php wp_insert_attachment( $attachment, $filename, $parent_post_id ); ?>
$filename (string) (optional) Location of the file on the server. Use
absolute path and not the URI of the file. The file MUST be in the
uploads
https://codex.wordpress.org/Function_Reference/wp_insert_attachment
You should first download it to temp dir.
If you wish to keep files on your CDN and simply save URI, consider adding a custom field and saving it there.
Related Posts:
- Loading template files from a subfolder in my theme?
- Display a different theme for not logged-in users
- How can I show more than 15 themes at a time in the admin menu?
- How to trigger function on theme delete?
- Make it possible to pick a color theme for specific pages
- OptimizePress Theme Overriding add_filter page_template
- Execute filter in theme as last
- How can I add class to every quote element?
- How to display message (with switch_theme hook) after deactivating My theme?
- What hook is the currently active theme’s functions.php file loaded on? [duplicate]
- after_setup_theme is called three times
- It’s okay if I do not write add_action()
- Posts as filtered list – expandable
- Using filter in the widget causes fatal error
- Fix warning: Missing argument
- Set custom directory in theme for page templates
- Webflow Interactions on WordPress site?
- Are immediately-called actions not usable in themes?
- Firebug and Chrome rendering two body tags
- Adding a wp_head hook from an included PHP file
- Hooking/Filtering theme name to add theme directory
- Fatal error Class-wp-hook, again, but not sure what’s triggering it
- How to change background color in the Notepad++ text editor?
- How to change or add theme to Android Studio?
- WordPress frameworks and parent themes [closed]
- Passing a parameter to filter and action functions
- Difference Between Filter and Action Hooks?
- Opinions and recommendations on the best barebones base theme [closed]
- Remove JSON API links in header html
- Using OOP in themes
- How to know what functions are hooked to an action/filter?
- Get a list of all registered actions
- WordPress hooks/filters insert before content or after title
- Where can I download WordPress themes from? [closed]
- How can I edit post data before it is saved?
- How can I allow the Editor Role to change Theme Settings?
- How do filters and hooks really work in PHP
- Trouble understanding apply_filters()
- What are all the available parameters for query_posts?
- Customizing a WordPress theme without changing it?
- Where can I learn to create my own theme?
- How do I turn off self-closing tags for markup in WordPress (for HTML5, or HTML4, for example)?
- how to add version of style.css in wordpress
- Does WordPress work without a theme?
- What is the role and history of the $content_width global variable?
- Adding admin-ajax.php to the frontend. Good or bad idea?
- How do I exclude plugins from getting automatically updated?
- get_template_part vs action hooks in themes
- How to move the sidebar in TwentyFifteen to the right?
- How to Link External jQuery/Javascript files with WordPress
- Installation failed: Download failed. No working transports found
- Issues with title-tag and document_title_parts
- What is theme-compat?
- Override parent theme translation on child theme
- WordPress Theme activation hook?
- Can wordpress theme folder name be changed freely and nothing technically happens
- Link to specific Customizer section
- What does exactly GPL license mean for my WordPress theme?
- Am I allowed to license my WordPress theme under the aGPL
- Is there any action filter/hook for validating a custom field before publishing the post?
- How do I change the header image height in Twenty Seventeen?
- Starter Theme vs Parent Theme? Pros and cons
- How to change the language for the front-end only?
- W3 Total Cache, CDN and theme files [closed]
- Best way to include Bootstrap in WordPress
- How to set thumbnail image for a (child) theme
- Different template of products for specific category. WooCommerce
- Show different theme for admin?
- How many filter/action hooks are healthy?
- How can I version the main CSS file?
- Add custom classes to anchor in wp_nav_menu
- Filter specific shortcode output?
- what the best way to include images from the template’s images folder?
- Earliest hook to reliably get $post/$posts
- Is it OK to remove theme credits from footer? [duplicate]
- Undefined offset: 0 in > […] /wp-includes/capabilities.php on line 1067
- How to pass/get data to/from the WooCommerce data-product_variations object?
- How can I get the title attribute from get_the_post_thumbnail()?
- Dash or underscore in theme folder name?
- No “Add New” Button. How to add new theme?
- Where to hook into post content?
- How do I add support to my theme for custom menus?
- “Unexpected error” on update requests
- How to prevent plugin, theme installation failures on WordPress?
- How do I white label my self-hosted site created by wordpress?
- What does (10, 2) mean when used with add_filter
- Do Child-Themes automatically load the Translation from the Parent-Theme?
- How to remove the Theme Customization Button from the dashboard and themes options page?
- Define custom Page Template without its own .php file
- Clarification on filters and hooks
- When cropping a header image, retain meta data (i.e. name, description, etc.) from original image?
- Best practices for a Style/CSS based theme options page?
- How to only hook on Single.php after content?
- How to create a new theme from scratch?
- Categorising themes by folders in backend
- Switching themes without losing widgets?
- Valid characters for actions, hooks and filters
- How to influence the information displayed on widget inside wp-admin
- How to use media upload on theme option page?
- Dynamic template serving, change theme_root using add_filter from current theme