I have already set up a child theme. Is it possible to add via FTP on my server a folder (preferably into the same child theme folder) called img and then link to the images in that folder from my pages and posts?
I tried using this path:
<img src="../wp-content/themes/theme-child/img/placeholder.png"/>
but that did not work.
You need to use the stylesheet directory instead. With a child theme, if you use the template directory it will go to the parent (see explanation on http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri).
It should be <img src="<?php echo get_stylesheet_directory_uri(); ?>/img/placeholder.png" />
Replace with the following code
<img src="<?php echo get_template_directory_uri(); ?>/img/placeholder.png" />
Yes you can. You can then access it by doing...
get_template_directory_uri().'/img/placeholder.png'
Tested script
src="<?php echo get_stylesheet_directory_uri(); ?>/images/welcome.png" alt="">
See Reference link
You can create img folder inside your Child Theme directory and can access it via the same way as core/parent theme directory reference get_template_directory_uri(). This will return the Child Theme directory URI as you're referring this in Child Theme.
<img src="<?php echo get_template_directory_uri(); ?>/img/childthemeimage.png" alt="Child Theme Image">
get_stylesheet_directory_uri()
will return the URL of the child theme while
get_template_directory_uri()
Will return the parent theme URL
Related
Wordpress loads all assets and links with an absolute URL including the domain name (e.g. <img src="https://example.com/cat.png">).
How to NOT include the domain name?
I tried editing the WP_CONTENT_URL and updating WP_SITEURL/WP_HOME with no success.
Is there a simple way of doing that?
You can do that by simply WordPress theme URL function get_template_directory_uri(). See the below link.
https://developer.wordpress.org/reference/functions/get_template_directory_uri/
It will give a full path to the WordPress theme. If your image path is like this
\wp-content\themes\your-theme\assets\images\image.jpg
then you can get that image path like below.
<img src="<?php echo get_template_directory_uri() . '/assets/images/image.jpg'; ?>">
I have an image folder in a child directory where some theme-related gfx is located. If I want to access it via:
<img src="<?php echo get_template_directory_uri();?>/assets/Logo.svg" />
It's trying to look for /assets in the parent theme directory.
How can I reference the child theme directory?
The function get_template_directory_uri always return the url of Parent Theme. Don't matter, where you called it.
To get the url of your Child Theme, you can use get_stylesheet_directory_uri(). So, your code will be:
<img src="<?php echo get_stylesheet_directory_uri();?>/assets/Logo.svg" />
I need to change relative paths to absolute paths in my WordPress page. My image links are broken in sub pages.
For example I need to change
../url/image.png
to
www.site.com/uploads/image.png
In your theme files, replace
<img src="../url/images.png">
with
<img src="<?php echo get_template_directory_uri(); ?>/url/images.png">
You can also do a search and replace. Search for ../ and replace with <?php echo get_template_directory_uri(); ?>
Hello I want to insert my logo to my wordpress site
<img src=”/wordpress/wp-content/themes/test/images/logo.png”>
that is my FTP Path to the image but it's still does not work. When I refresh my site a image icon appears but it does not show my logo... Why? It seem that the PATH don't work right? Any suggestions what could be wrong or is there any special WP Query I need to use? Seems like it? Can't find tho..
Thanks
You shouldn't be using an absolute path to an image file. This would be useful if you wanted to get the files attributes in PHP but not when you want to show the image on the page.
There are two functions you should familiarise yourself with:
get_template_directory() - This will get the absolute path to the theme directory.
get_template_directory_uri() - This will get the theme directory URI.
Correct way to link to the image file:
<img src="<?php echo get_template_directory_uri(); ?>/images/logo.png">
Don't forget to add an alt attribute.
Use below function for site URL
site_url();
replace this with you img code
<img src="<?php echo site_url("/wp-content/themes/test/images/logo.png"); ?>">
use something like this
<img src="<?php bloginfo('template_url'); ?>/images/logo.png" />
I have Wordpress deployed on Ubuntu server.
in the folder where my theme is I have index.php. In the same folder I have a file: "logo.png"
in index.php I have the following line:
<img src="logo.png" alt="" />
Yet, i get a broken image when browsing there. How can that be? The file is right there, sibling to index.php in the folder!
It's going to look for logo.png in the root directory of the website, not in your theme folder. You need to add the path to your theme directory to the image tag.
I got it, should have used:
<?php bloginfo('template_directory'); ?>
so that the right path is taken at runtime for my theme folder.
try something like this
<img src="<?php bloginfo( 'template_url' ); ?>/logo.png" alt=""/>
You can also specify the full path of the logo.png file in image source so that it will grab the logo image from the source rather then looking in your parent directory for the logo image
<img src="*Full path of logo.png file*" alt="" />