Customize Magento template - php

I've installed some theme, which has header logo defined in header.phtml like this:
<img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" />
I don't really want to alter this template, also in that .phtml file it says not to edit it. How can I override this getLogoSrc most efficiently?

In the web admin, go to System>Configuration>Design and scroll down to Header>Logo Image Src. Insert the filename that you have saved in /skin/frontend/default/new_theme/images/ and click Save.

Go to your template's images folder e.g.: /skin/frontend/default/new_theme/images/
and replace the logo image in that folder with your new Logo

Related

How to display images in Wordpress

I'm doing a test for a job and I already have a folder with some images and a HTML & CSS already done. They just want me to put this in Wordpress.
How can I display this images that I have into the HTML or functions?
Ex:
<div class="container container-nav w-container"><img src="images/Logo_Trust_White.png" alt="">
This is what i have in my HTML file. Can I use "wp_get_attachment_image('imagename');"?
Thank you already!
If you want to display the image file located within your theme directory, just specify the location with the img tag, and style it with CSS.
<img src="<?php echo get_template_directory_uri() . '/images/Logo_Trust_White.png'; ?>" />
Reference : https://developer.wordpress.org/themes/functionality/media/images/
The function wp_get_attachment_image only gets an image that was uploaded to wordpress, it doesn't output an image in the content of the post.
You have to output the content of the post for your example image.
Like: echo $attachments['post_content'];
you're passing in the post id (54 in your example; typically $post->ID in WP parlance) to wp_get_attachment_image(). As can be seen in the codex, you're supposed to use the attachment id (see $attachment_id below):
wp_get_attachment_image( $attachment_id, $size, $icon );
In other words, you've got to do something like this:
$image_attr = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium');
In general I would avoid using theme specific images in the content,
because when you change and delete the old theme, then they are gone.
So I would consider using /wp-content/uploads/ for content images.
What is a Custom Logo?
Using a custom logo allows site owners to upload an image for their website, which can be placed at the top of their website. It can be uploaded from Appearance > Header, in your admin panel. The custom logo support should be added first to your theme using add_theme_support(), and then be called in your theme using the_custom_logo(). A custom logo is optional, but theme authors should use this function if they include a logo to their theme.
https://developer.wordpress.org/themes/functionality/custom-logo/
Replace your img tag with
<img src="<?php echo get_template_directory_uri(); ?>/images/Logo_Trust_White.png" alt="">
Place your images folder in the wp-content folder
Using get_template_directory_uri() to link a static image with its correct path in html :
<img src="<?php echo get_template_directory_uri(); ?>/images/logo.png" width="" height="" alt="" />
Place you images in your active theme. Path will be wp-content/themes/{theme-name}.

how to insert custom images and html in wordpress

I'm creating a new WordPress Theme and I want a media folder to contain some images that are not considered to be posts.
e.g. themes/theme-name/media/sampleIMG.jpg
adding
<img src="media/sampleIMG.jpg">
in my theme folders index.php leads to an 404 error code output because apparently my local apache server is requesting that file from a different directory:
/html/media/sampleIMG.jpg
What am I doing wrong?
<img src="<?php echo get_stylesheet_directory_uri();?>/assets/images/logo.svg" alt="" class="svg logo">
Using get_template_directory_uri() to link a static image with its correct path in html :
<img src="<?php echo get_template_directory_uri(); ?>/media/sampleIMG.jpg" alt="theme logo" />
Note: get_template_directory_uri() return absolute path to the
directory of the current theme.

Wordpress logo image in header.php

I'm trying to create a custom theme in Wordpress, and currently I'm working on my header.php file. However, I'm unable to display my logo image. Here's the code for the same:
<body>
<div class = "container">
<div class = "five columns">
<img src = "<?php bloginfo('template_url'); ?>/img/sem.jpg" title = "<?php bloginfo('title'); ?>">
</div>
</div>
</body>
The sem.jpg image is stored inside the img folder inside my root project directory. However, the logo doesn't seem to be displayed on my webpage. I have also tried using images of other formats, but none of them seems to work. I have also called the get_header() function inside my index.php.
What seems to be wrong in my code?
The reason seems a permissions problem.
You can set permission 777 to the logo image via command line, typyng:
chmod 777 /path_to_your_file
or set using right click on the logo file, and change properties.
You can't view your image because you have got set wrong permissions on your image. Open your FTP client, connect to your site and find your image, right click it and chosse Change file permissions and change them to 644.
File permissions should look like this:
http://s12.postimg.org/rxb25ziy5/Untitled.png
Try This.
<body <?php body_class(); ?>>
<div class = "container">
<div class = "five columns">
<img src="<?php echo get_template_directory_uri(); ?>/img/sem.jpg" alt="<?php bloginfo('title'); ?" />
</div>
</div>
</body>
Enjoy..!!
user this wordpress plugin
it will help yo upload logo using wordpress admin and you can change any time with edit header.php file.
Use below function to print logo
echo theme_logo();

Custom wordpress theme images not displaying

I'm building my first WP theme. My images are linked this way:
<img src="<?php bloginfo('wp-content/themes/SRPrint'); ?>images/freephone.png" />
Obviously theme folder called SRPrint and inside it there is an images folder.
Can't understand why images do not show up? I don't know any php so I asume problem is in php code? Images specified through style.css show up ok.
Please help.
Link to test site http://www.designstest.co.uk/
you must use <?php bloginfo('template_directory'); ?>/images/freephone.png to get the images in the current theme.
See: bloginfo
<img src="<?php bloginfo('template_url'); ?>/images/logo.jpg" alt="<?php bloginfo('name'); ?>">
Change all image to src="
<?php echo get_template_directory_uri();?>
/images/picname.jpg"

How can I get the image url in a Wordpress theme? [duplicate]

This question already has an answer here:
How can I get the image url in WordPress?
(1 answer)
Closed 2 years ago.
I am developing a theme for wordpress. And I have many images in 'images' folder. But when I take the page in browser it is not comming.
My code is
index.php
<ul>
<li><img src="images/mindset.jpg" width="145" height="32" /></li>
Is there any function for getting the image path in wordpress ?
src="<?php echo base_url()?>your_theme_dir/image_dir/img.ext"
As well
src="<?php bloginfo('template_url'); ?>/image_dir/img.ext"
get_template_directory_uri();
This function will help you retrieve theme directory URI, and can be used with your images, your example below:
<img src="<?php echo get_template_directory_uri(); ?>/images/mindset.jpg" />
I had to use Stylesheet directory to work for me.
<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/image.png">
You need to use
<?php bloginfo('template_directory'); ?>
It returns the directory of the current WordPress theme.
Now for example, if your theme has some image named example.jpg inside some folder name subfolder folder in the images folder.
themes
|-> your theme
|-> images
|->subfolder
|-> examples.jpg
You access it like this
<img class="article-image" src="<?php bloginfo('template_directory'); ?> /images/subfolder/example.jpg" border="0" alt="">
src="<?php bloginfo('template_url'); ?>/image_dir/img.ext" worked for me for wordpress 3.6 i used it to get header logo using as
<img src="<?php bloginfo('template_url'); ?>/images/logo.jpg">
If you are developing a child theme you can use:
<img src="<?php echo get_template_directory_uri(); ?>-child/images/example.png" />
get_template_directory_uri() will return url to your currently active theme (parent theme), then you add -child/, then add path to your image (the example above assumes your image is at <child-theme-directory>/images/example.png)
I strongly recommend the following:
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img-folder/your_image.jpg">
It works for almost any file you want to add to your wordpress project, be it image or CSS.
If your img folder is inside your theme folder, just follow the example below:
<img src="<?php echo get_theme_file_uri(); ?>/img/yourimagename.jpg" class="story-img" alt="your alt text">
You asked of Function but there is an easier way too. When you will upload the image, copy it's URL which is at the top right part of the window (View Screenshot) and paste it in the src='[link you copied]'. Hope this will help if someone is looking for similar problem.

Categories