The get_attached_file()
function returns the path to a file based on the attachment ID:
$FeaturedImage = get_attached_file( get_post_thumbnail_id() );
Getting the path to a specific size is more complicated. WordPress stores the filename for resized versions of the images in as attachment metadata, that can be retrieved with wp_get_attachment_metadata()
. Once you have the filename of the resized version, you just need to replace the original filename in the path with the resized version’s filename:
$image_id = get_post_thumbnail_id();
$image_meta = wp_get_attachment_metadata( $image_id );
$image_path = get_attached_file( $image_id );
if ( isset( $image_meta['sizes']['homepage-column1']['file'] ) ) {
$image_path = str_replace( $image_meta['file'], $image_meta['sizes']['homepage-column1']['file'], $image_path );
}
Related Posts:
- How to get the path to the current theme?
- Symbolic Links on dev box with plugins and stylesheets
- permalinks with get variables
- WordPress plugin how to run function when button is clicked
- Use an empty page to build custom plugin output
- Add Post and Comments menu no longer visible
- Plugin base URL
- Creating a path in a plugin to call a function
- URL rewriting must be activated manually for my plugin
- 404 errors after plugin options update and category base change
- Why doesn’t flush_rewrite_rules run on plugin activation?
- Auto save permalink setting page with the plugin activation
- Help With Rewrite_Rules For a Custom Plug-In
- Append varible to url or set session
- How can I turn a custom wordpress page into a product page?
- rewrite URL based on selected taxonomy for post page
- Problem with dinamic add_rewrite_rule()
- Remove custom post type slug from URL and add taxonomy Slug
- add_rewrite_rule behaving strangely
- custom permalink’s rewrite rule for page id
- Show content without a post
- Plugin path comes wrongly
- How to create new content type and flushes rewrite rules without visiting the permalinks page?
- Forward an old url rewrite scheme to a new one?
- Changing permalink structure breaks link to .php file which generates files dynamically
- Loading Images from Javascript on the Front End
- wp_insert_post generated mixed permalinks
- How to link to custom “archive like” page with custom permalink rules “dynamically”
- Add variables from rewrite rules to query var
- Home page is not loading, where in other pages are displaying on the site
- I’m including a html file in my plugin, but it can’t find its css or js files
- Get the current post/page URL with plain permalinks
- Adding body class in author page for custom role
- Author Meta in Author URL Link
- WordPress plugin how to run function when button is clicked
- Get (eventual) permalink from post within Edit Post in Admin panel
- WordPress permalink setting
- Get URL of Post You Are Editing
- How to use permalink query to go to specific tabs in posts
- Custom rewrite, url path with parameters to a page
- How do I create a custom role capability?
- Export data as CSV in back end with proper HTTP headers
- How to call a plugin function from index.php
- Calling the widget id of a mult-instance widget from inside the widget?
- Do I need to call do_action in my plugin?
- WooCommerce get Shipping Class of product from either the product id or the order after order is completed
- Dequeue script, but still use wp_localize_script to pass vars
- Can I add pages to my custom menu via script?
- Programmatically Selecting Theme Based on URL
- Why is print_r returning $classObj->userObj in several places on site
- Is it possible to load plugin from console with core ?
- use __($str) to translate strings (symfony/twig)
- Plugin development: is adding empty index.php files necessary?
- Add a Custom Permalink option in the Permalink Admin Screen?
- Customize multisite site creation with user data
- Adding plugin settings link upon activation
- How to create multiple Gutenberg blocks in one plugin
- Proper way to run wp_query from inside a plugin
- Buddypress function and global $bp question
- Custom plugin: Loop through taxonomy types and update columns for all types?
- How to add setting section in custom post type [closed]
- Maximum lifetime for nonce
- How to Display my HTML form in my Custom Plugin?
- Where to add hooks in a class
- Adding rewrite rule dynamically
- Incorporate small angular feature in my wordpress site
- Bootstrap doesn’t work on admin menu page-How to override wp-admin style?
- Use just a shortcode from another page
- Using arbitrary paths in page urls
- How can I avoid conflicts between plugin and theme?
- How to control an elements classes from multiple Gutenberg sidebar controls?
- WordPress class, using add_action to call member function does not work
- random code at the end of file after plugin upload
- How Can I add Fields in wp-option table?
- $wpdb->prepare with LIKE and sprintf
- Why in this archive page that call query_posts() function show only the last 10 posts?
- Quasi-custom API Call Plugin
- How can I show posts for a single category?
- WP ajax requests not stacking?
- In wordpress plugin wp_signon shows error
- Working of foreach loop with array
- Grandchildtheme (plugin) add header.php (not exist in child theme)
- $wpdb->update Issue
- Is there any way to pass messages from a script to a redirect target in a hidden fashion?
- Load specific page when a custom URL is hit
- Trigger function on Remove block or add new block in Gutenberg JavaScript
- Trying to rename a file upload as the hash of file content on wordpress
- Fatal error: Uncaught Error: Using $this when not in object context
- want to confirm popup with “Yes” and “No” button when user click on add to cart
- do I need to sanitize a shortcode’s function input?
- Email content as comment
- Modify search form with plugin
- Organising and completing posts (mark as read and hide)
- When using an options array the Settings API isn’t creating the database record
- the correct way to use options from settings page [closed]
- I want to add post meta for picture thum during submit for revision
- How to synchronize an e-commerce site and a pharmacy management software?
- woocommerce features to add product along with link
- Extend WP_List_Table class – Edit wp_usermeta – WPPB.me Boilerplate – Action error
- Programmatically creating posts based on external JSON feed (asynchronously)