Insert logo header.php wordpress - wordpress

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" />

Related

src of the custom-logo img-tag is missing and not rendered in Wordpress

I'm using the template "Twentyseventeen" and created a child theme of it.
Now I added the_custom_logo(); to header.php and the custom-logo link is rendered,
but without the img src. So I have a blank space. I searched now for hours and can't find the reason. Even if I switch back to orignal Twentyseventeen theme the img src was missing. Well I'm not very famiiar to wordpress and if anybody could help me to fix this? Thank you
Hi :) try to add <img> like this
<img src="<?php the_custom_logo();?>"/>
In my theme I use This:
<div class="logo">
<a href="<?php echo get_home_url(); ?>">
<?php $logo_id = get_theme_mod( 'custom_logo' );?>
<?php echo wp_get_attachment_image( $logo_id , 'full' ); ?>
</a>
</div>
I hope that it help you :)
Possibly you don't have custom logo set in the backend or it needs a reset.
Go to the Admin Dashboard > Appearance > Customizer > Site Identity
Check if you've set the custom logo there. If it is set, remove it
and reset it.
If you don't see any option to set custom logo there, your theme doesn't support custom logo option. In this case the_custom_logo() or related functions will not work. Read this guide to add support for custom logo and then using the URL or printing the logo with markup.

How to remove hardcoded domain name from WordPress links?

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'; ?>">

Change the Path of wordpress featured image

I am trying to change the current path obtained bywp_get_attachment_url(get_post_thumbnail_id)
Now I get the uri as http://localhost/velocity/wordpress/wp-content/themes/velocity/images/pic01.jpg.
but I want to change the uri as http://newhost/velocity/wordpress/wp-content/themes/velocity/images/pic01.jpg
any idea?
The image you're referring to isn't an attachment image...it's a theme asset.
If you're properly including this in your template, changing hosts won't be a problem and the URL will automatically update. The following is an example of how you could be including the src in your template, using get_stylesheet_directory_uri():
<img src="<?php echo get_stylesheet_directory_uri() . '/images/pic01.jpg'; ?>">

How to change relative paths to absolute paths in WordPress?

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(); ?>

wordpress: how to add a custom static HTML page template with some images in it

i have created a custom static html page
by adding a php file in
wp-content/themes/myactivetheme/
containing essentially
<?php
/*
Template Name: test
*/
?>
<div><p>blablabla</p>
<div><img src="content/images/thumb/00500_Partition_Vivaldi_Printemps.jpg" /></div>
i have placed the corresponding image file in
wp-content/themes/myactivetheme/content/images/thumb
When creating a new page with the dashboard using this test template , the text is displayed but not the image, why?
Probably the source address for the image is wrong. Don't use relative links. For example:
Instead of:
<img src="content/images/thumb/00500_Partition_Vivaldi_Printemps.jpg" />
Use:
<img src="<?php bloginfo('template_url'); ?>/content/images/thumb/your-image.jpg" />
It will help Wordpress to find the exact path to display your image.
Relative URIs will be relative to your WordPress index, so WordPress will look for the image in the wrong place. You could
move the image
hard code the image url
do it the clean and right way, which is <img src="<?php echo get_stylesheet_directory_uri(); ?>/content/images/thumb/00500_Partition_Vivaldi_Printemps.jpg" />
the image file had to be placed in
/wordpress/content/images/thumb

Resources