What is wrong with my PHP code? - php

I have been seriously been looking at this forever! I'm going out of my mind And can't figure out why my images are not displaying in my custom made footer.
I have firefox with firebug and it is simply saying that the url is failing to load. so I copy and pasted a url to an image that is currently working and is being shown via the background property in CSS just fine. (thats the top one that says dakota jones). copy and pasting the exact img src proves it still not to work.
my folder is images. My functions.php is right outside. the hierarchy is correct. what the heck?? The testing text in the p tags work just fine. uhuhuhu
Somebody help me! I'm using wp and genesis theme.
add_action('genesis_before_footer', 'include_sponsors');
function include_sponsors() { ?>
<div class="sponsors">
<p>This is testing text</p>
<img src="images/dakotajonesheader3.jpg" alt="Smiley face" height="42" width="42" />
<img src="images/tfobw.png" />
<img src="images/basskingbw.png" />
<img src="images/bighawgbw.png" />
<img src="images/kbw.png" />
<img src="images/mccoybw.png" />
<img src="images/nfcbwpng" />
<img src="images/rayjusbw.png" />
<img src="images/rrbw.png" />
</div>
<?php }

Use WordPress' inbuilt function:
<?php
bloginfo('template_directory'); ?>/images/dakotajonesheader3.jpg
?>
.. which will reference /wp-content/themes/your-theme/images/dakotajonesheader3.jpg

Wordpress dynamically rewrites URLs, so the URL you use to access a page is not the same as the path to the scripts that are running on the server. So you might request your page with example.com/Home. But your images are not stored in example.com/Home/images, which is where you're telling your browser to look. They're stored in example.com/wordpress/wp-content/themes/your_theme/images. So you have to give the absolute path to the images to the browser in your <img> tags.

Carson is correct, and you can use absolute paths to your images. Alternatively, if you want to avoid using absolute paths, you can call your images using bloginfo('template_directory');
For example:
<img src="<?php bloginfo('template_directory'); ?>/images/dakotajonesheader3.jpg" alt="Smiley face" height="42" width="42" />

Related

<img> tag is not working in php Codeigniter

<img> tag is not working in PHP Codeigniter
<img src="<?php echo $p_info['p_img']; ?>" alt="Product Image is not uploaded" height="700px" width="500px" />
Output of $p_info['p_img'] is giving correct path where image is saved.
and i uploaded the image now i want to show that image in edit process
<img src="<?php echo $p_info['p_img']; ?>"
alt="Product Image is not uploaded" height="700px" width="500px" />
<?php echo $p_info['p_img']; ?> should be a path which access images from the project directory not from a local path.
C:/xampp/htdocs/squadfreetry/assests/img/products_images/Acne Free (1).jpg this is wrong & will not show image.
You have to save image path starting from /assests/... and to access it by calling base_url() at first & followed by saved path in DB.
Code should be like:
<img src="<?=base_url().$p_info['p_img'];?>"
alt="Product Image is not uploaded" height="700px" width="500px" />
Where $p_info['p_img'] is a path starting from /assests/..
Sometimes if you view source using certain browsers (firefox, chrome), it omits the /> tag. Try view source using a notepad or something, it should display proper /> tag.
If you want a shorter tag, use this:
<?php echo img(array('src'=>'image/picture.jpg', 'alt'=> 'alt information')); ?>
Here is detailed information:
https://codeigniter.com/user_guide/helpers/html_helper.html#img
More examples:
<img src="<?php echo base_url('assets/uploads/' . $gambar)?>" alt=""/>
and
<img src='<?php echo base_url("assets/uploads/$gambar")?>' alt=""/>
Note: Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.
Please try the below way:
I am assuming that your project folder is Cart -> images/your desired image
when you do file uploading then you have to save the image in folder -> images
and the image name in database.
so to access it replace your image code like this:
<img src="<?php echo base_url(); ?>images/<?php echo $p_info['p_img']; ?>" alt="Product Image is not uploaded" height="700px" width="500px" />
On CodeIgniter 4 you can use the img function, from html helper.
Adds the helper on controller -> helper('html');
Generates the img tag on the view -> echo img('public/img.png').

How to call a function inside img src

I have below code but don't want to encode the image as Base64 just link the image and get it with same function.
<img src="data:image/png;base64,'.base64_encode(file_get_contents(get_field('email_logo', 'option')['url'])).'" alt="The Domain" />
How to call the function inside img src?
You've not shown us how this bit of code connects to the PHP around it. Assuming that there is a closed PHP block before hand, rather than this appearing in a print or heredoc...
?>
...
<img src="data:image/png;base64,
<?php
print base64_encode(file_get_contents(
get_field('email_logo', 'option')['url']
));
?>'" alt="The Domain" />
If you want only the link and it's correct as it is:
<img src="'.get_field('email_logo', 'option')['url'].'"/>

How to correctly use get_template_directory_uri() WordPress function to load an image that is in a subfolder of my theme?

I am pretty new in WordPress and I have the following doubt about how to insert in my homepage an immage that is in a subfolder into my theme directory.
So I have the following situation: Into my custom theme directory I have the following folder that contains a jpg immage: /assets/img/flexslider/flex-1.jpg
Now in my header.php file I have something like this:
<li>
<img src="assets/img/flexslider/flex-1.jpg">
<div class="flex-caption">
<p class="flex-caption-text">
<span>Lorem ipsum</span><br>
<span>sit dolor</span><br>
<span>adipiscing elitur</span>
</p>
</div>
</li>
Obviously, when I load the page, the immage flex-1.jpg is not loaded because there is not the right path (infact using FireBug I obtain that it try to load the assets/img/flexslider/flex-1.jpg immage) so I think that I could use the absolute path but this is pretty orrible !!!
So I am thinking to use the get_template_directory_uri() function provided from WP to do this and I have try to change the previous code in this way:
<li>
<img src=<?php get_template_directory_uri().'/assets/img/flexslider/flex-1.jpg' ?>>
<div class="flex-caption">
<p class="flex-caption-text">
<span>Lorem ipsum</span><br>
<span>sit dolor</span><br>
<span>adipiscing elitur</span>
</p>
</div>
But don't work and using FireBug I can see that load nothing, infact in my brower source code I have:
<img src="">
Why don't work? What am I missing?
Tnx
Andrea
I hope it will work:
<img src="<?php echo get_template_directory_uri(); ?>/assets/img/flexslider/flex-1.jpg" />
If your assets folder inside theme.
please try :
<img src="<?php print(get_template_directory_uri()); ?>/assets/img/flexslider/flex-1.jpg" />
just check for slash, if double before "assests", remove static one.
You can also use:
<img src="<?php bloginfo('template_url'); ?>/images/yourimage.jpg">

Images wont show in wordpress

So,
My images are located in wp-content/themes/mytheme/images
Originally, when i converted my site from html/css the path looked like this:
<img src="images/myimage.png" alt="some text" />
That did not work and I have now tried two diffrent solutions:
<img src='<?php get_template_directory_uri(); ?>/images/myimage.png'>
and
<img src="<?php bloginfo(); ?>images/myimage.png">
Have i missed something? I am new to wordpress an php and would appreciate some help. Thanks!
You almost had it. You left off echo.
http://codex.wordpress.org/Function_Reference/get_template_directory_uri
Output the URI
<?php echo get_template_directory_uri(); ?>
The full result is:
<img src='<?php echo get_template_directory_uri(); ?>/images/myimage.png'>
I recommend you use Drupal if you haven't gotten too far with WP already. :)
Try
get_stylesheet_directory(). '/images';
/images/myimage.png">
This will return the images directory path in the currently selected theme, even if it's a child theme.
Function Reference/get stylesheet directory

How to link images in kohana?

I'm getting started using Kohana framework. How do I properly link images? I'm linking images using the usual way:
<img src="../../resources/images/img01.jpg" />
I'm using dreamweaver, and I can see that the link is correct. Since I can see an image in the preview:
The link is still the same when I reference the image based on the controller.
Best way to use full (base)paths:
<img src="<?php echo url::base() ?>resources/images/img01.jpg" />
or:
<img src="<?php echo url::site('resources/images/img01.jpg') ?>" />
You need to use absolute links. Either use html::image(), or prefix your image with url::base(), or use url::site(). There's lots of options, read the documentation.

Categories