To grab the img tag as a variable:
get_the_post_thumbnail ( int $post_id = null, string|array $size="post-thumbnail", string|array $attr="" )
or if you want to outright echo it:
the_post_thumbnail ( string|array $size="post-thumbnail", string|array $attr="" )
Most things like the post content, excerpt, title etc, are acquired using functions like this so that filters and hooks can be used. I’d recommend you use the get_
versions rather than the the_
versions, so that proper escaping and sanitisation can be applied
Further reading:
Related Posts:
- What’s the difference between home_url() and site_url()
- Prevent “main” WPMU site_url() being returned in functions
- Custom page with variables in url. Nice url with add_rewrite_rule
- Is it possible to use a forgot password url filter?
- Create Custom URL structure for specific Post category
- How can I rename the WordPress AJAX URL? [duplicate]
- Ninja form Redirect depending on text field content [closed]
- wp-comment author- url +, email filter hook
- Removing custom meta data
- WordPress on AWS Auto scaling and ELB giving 503
- WordPress converts media extention URL automatically to video player
- meta tags doesnt fetch data from permalinks
- Get arguments from URL
- Add unique id to Preview URL
- How can I set the SRC URL of the custom logo image?
- Need to convert image url to a Base_64 data url with wordpress function..
- Protect get_query_var from manual input in url
- Problem with images URL after filter applying
- How i can get the URL?
- include w_thumbnail_src in function?
- Create Custom URL structure for specific Post category using Post ID instead of post name
- Fetch URL parameter
- how can I change all wordpress media file url to custom cdn url?
- Custom route and extract data from slashes and parameter
- reWrite wp-content url to point on my cdn
- How to Override Page Template if URL matches query?
- Add #primary at the end of navlink permalinks on single posts
- Set URL Parameter Post Layout As Default
- Using Switch Statement to Change Image According to Last Digit of Topic ID
- How to add a meta information to the URL?
- How do I change the URL returned by next_posts_link()?
- Function in functions.php by url
- Solution to render Shortcodes in Admin Editor
- How to run a function every 5 minutes?
- Modify Admin Bar Link
- How to override admin-bar style
- WP 4.4. responsive loads normal image after loading the responsive image
- How can I tell if I’m on a login page? [duplicate]
- Get Category and Excerpt From wp_get_recent_posts
- Two different menus for two different locations?
- Error after editing functions.php
- How do I properly register bootstrap JavaScript into WordPress functions.php?
- Manipulate Output of wp_list_something: select menu instead of li’s
- how to fix Warning: Use of undefined constant _ – assumed ‘_’ (this will throw an Error in a future version of PHP)
- restore_current_blog required after switch_to_blog, if I use that in a function?
- ‘is’ functions and ‘get_query_var’ not working
- How Can I Expand the WordPress Customize window without any Plugin?
- “is_new_day()” alternative for years?
- How to hide a plugin metabox for non admins when a user adds a new post
- Getting Featured Image Caption to Only Show if Populated
- How do I create page navigation linking to each H2 within the page? [closed]
- Allow Post Author to be 0 on Update
- How can I make a widget shortcode to control all the widgets?
- admin-ajax.php + load-scripts.php hanging for minutes
- Unique sequential reservation code
- Show image exactly defined to a width
- wp-admin won’t load after setting wp-login custom url
- Is `is_sidebar_active()` deprecated, and showing error?
- How to return hook data when multiple parameters are present?
- Generate featured images old posts
- How to add_filter html template to middle of content
- Use /prefix/postname as a slug in post_name?
- Send email to admin user when custom post type is created
- Pass variable from action back to template
- Some questions about how proper add 2 CSS file in a WordPress theme?
- Test if a post exists by category and date
- Where to call my pagination function?
- How do I pull excerpts from pages?
- How to map numbers utilizing array function
- Check if a value exists in database table
- Add element to widgetpage
- Using functions.php to include code that’s processed inline
- why can’t i add front.css to my frontpage.php
- “All posts” in the category widget
- Are innerHTML elements visible to jQuery functions?
- how to display a page before the home page
- How d0 i get the number of attachments in the post
- Removing WPML Items From the WordPress Admin Bar
- This code is supposed to only allow user to be authenticated if accountVerified is equal to 1, but it still allows user to be authenticated otherwise
- Get webpack to work on child theme
- Passing function arguments via a shortcode
- Hide ‘add to cart’ when certain value in dropdown is selected
- How do you insert code into the sidebar?
- Test CDN link from function.php or wp_enqueue_script/style?
- Help with with my function for wordpress
- Widget is displayed in two places
- Auto Resize embedded videos player
- Can site visitors view functions.php file?
- Combine multiple menus using the filter wp_nav_menu_items
- WordPress function with attribute pass to template
- I see edit instead of read more
- How to replace words in my posts and saved new words
- Why might wptexturize have become re-enabled?
- Custom Nested WordPress Comments with avatar
- Having problems loading Jquery in functions.php
- Functions file mods and CPU
- How can I append and prepend something to all post hyperlinks without using ::before or ::after? PHP hook solution?
- How to overwrite ‘read more” text for artmag theme
- Retrieving next_post_link() and previous_post_link() in functions.php
- Problem with woocommerce recalculating tax on completed orders