You’ll want to use wp_get_attachment_image_url()
or wp_get_attachment_image()
. You just pass them the ID of the image in the database and the size you want.
wp_get_attachment_image_url()
gives you the URL of the image:
echo wp_get_attachment_image_url( $attachment_id, 'large' );
// http://example.com/wp-content/uploads/2017/01/image-1024x1024.jpg
While wp_get_attachment_image()
gives you a full image tag:
echo wp_get_attachment_image( $attachment_id, 'large', false, [ 'class' => 'my-image' ] );
// <img src="http://example.com/wp-content/uploads/2017/01/image-1024x1024.jpg" class="my-image" etc...
If you do want it from your theme folder, then a better method these days is get_theme_file_uri()
, because it supports being filtered or being replaced by child themes:
echo get_theme_file_uri( '/img/bridge_ico.png' );
Related Posts:
- Can I install/embed WordPress on a ‘single page’?
- Why isn’t my link attribute getting my css?
- Display pages from specific page template
- Styling best practices for single pages/templates
- Getting only direct child pages in WordPress with get_pages
- Adding first / last CSS classes to menus
- How to add a .php file to WordPress
- WordPress Admin Bar pushed Sticky Footer off the bottom of the page
- Check if a menu is empty?
- How to target with css, admin elements according to user role level?
- load/require specific php files for specific pages/templates/post types
- the_author_posts_link css class
- WordPress Shortcode and Dynamic CSS
- How to change “Shipping Calculator “field label on Cart Page – woocommerce? [closed]
- “wp_enqueue_style();” don’t load new edited style
- Best way of adding CSS which can be manipulated by the user via theme option panels?
- Need help on WordPress and php
- Multiple pages on one with different HTML
- functions.php not adding css to website?
- Exclude pages with certain template from wp_list_pages
- wp enqueue style and style sheet depth
- WordPress Customizer not setting default value upon initial install?
- Theme Customizer – Dynamic CSS PHP File
- CSS saved & enqueued, but wordpress doesn’t load css text, only file
- Using PHP in a Stylesheet (possibly a “.htaccess” problem?)
- Loading page template into shortcode
- WordPress loop specific thumbnail size
- WordPress doesn’t include css
- Understanding child theme functions.php
- wp_enqueue_style with style.php and WordPress functions
- Help with a custom page template – listing contents of childpages?
- Is it possible to use the featured image of a page as a css background without inlining?
- if file_exists not working with wp_enqueue_style
- Easiest way to show total number of subpages
- Want to create Child theme, but already edited Parent theme css files and some php files
- Switching between custom templates in a post type of the admin menu
- Minify HTML, CSS, JS with PHPWee?
- Using PHP to toggle stylesheet and header image, set in cookie
- Archive dropdown styling not applied
- How to display a value from a radio button in the options menu in wordpress
- How should I best target dynamically served content?
- Different background-image by category
- page template for attachement page?
- Style every second widget?
- How to scale image with equal width and height without distortion?
- Add a Different CSS Class Into The Body Tag of Different WP Pages
- php syntax – how to concatenate properly – echo bloginfo(‘stylesheet_directory)
- wp nav menu: add attributes to menu items [duplicate]
- Changing the template hierarchy
- WordPress override bloginfo variable
- How to enqueue CSS and JS only on specific template?
- Put CSS inside a PHP file and include it the right way
- Shortcode content output but not in correct place
- Custom Template 404 for specific custom post type
- An unwanted inline style is added to my body tag
- Displaying theme options in css
- Show post in slider
- Problem adding class to body_class
- Add a custom stylesheet for BlackBerry
- How can I hide Home in my menu in a specific page?
- Missing sidebar parameter “fix” – before_content
- Get different images for mobile and desktop with php, advanced custom fields without using js and ajax
- How Display Posts on category
- How to stop featured image thumbnail [set as background image] on blog index page just repeating same image across all posts
- Slider loading issue
- Plugin CSS not enqueing
- Hide Hamburger Menu On Specific Page (Front Page/Home Page)
- Parent theme CSS overriding child CSS rules
- how to remove metadata from the posts of my blog?
- Showing content from one page on another
- How to style options page in dashboard?
- Theme Options Page – User Updates Logo
- how could I load a different template part by page
- How to use my style.css file outside of wordpress subdomain?
- Dynamic Stylesheet loads but doesn’t finish
- Page Automatically Generated from Theme?
- How to add date to navigation bar
- Selectbox in admin panel function linking to CSS
- How to hide all child pages with post_query?
- Using if/else statements with output from theme options
- Is there CSS to expand the gallery limit on Index Pages?
- How to design a table based on css values set from admin/dashboard
- Can’t access variable outside for loop
- Incorrect MIME type for assets with Valet
- Change title only in dynamic page
- How to add condition in wordpress loop? [closed]
- Dynamic content in template
- Populate editor with some content of a page with a page template
- Customize position of social icons in upme plugin [closed]
- Best way to schedule daily change in CSS parameter
- Css loads very slow [closed]
- How to get the value of input hidden html from text editor to custom page template?
- Gravity form built in Captcha
- How does wp_enqueue_scripts work?
- Different post styles depending on category
- How create a Shortcode with hover and complex options
- WordPress Multiple Navigation bars
- two columns of posts on homepage, one of them “favorites”
- Auto 301 to full post permalink? (using : /archive/%post_id% to %post_name% )
- Whats the proper way to use a php stylesheet in a wordpress theme? [duplicate]