I've encountered this issue a couple times but have always found a "hack" way around it. Is there a special way to link an image in a WordPress template to an outside url beyond the typical a href tag? Here's the images I'm trying to link to outside urls:
<div class="socialMedia">
Follow Us: <br />
<img src="<?php echo get_bloginfo('template_url') ?>/images/facebook.png" alt="facebook"/>
<img src="<?php echo get_bloginfo('template_url') ?>/images/twitter.png" alt="twitter"/>
<img src="<?php echo get_bloginfo('template_url') ?>/images/googleplus.png" alt="google plus"/>
<img src="<?php echo get_bloginfo('template_url') ?>/images/instagram.png" alt="instagram"/>
</div><!--.socialMedia-->
<div class="socialMedia">
Follow Us: <br />
<a href="<?php echo get_bloginfo('template_url') ?>/images/facebook.png" target="_blank" > <img src="<?php echo get_bloginfo('template_url') ?>/images/facebook.png" alt="facebook"/> </a>
</div><!--.socialMedia-->
did you mean it!!?
Related
I create a block from configuration. Inside this block, I write this code...
<div class="provider-bg" id="provider1">
<img alt="" class="img-responsive" src="<?php echo base_path().path_to_theme() ?>/images/provider-1.jpg" />
</div>
Then, I save with PHP in text format.
My virtual host is ... http://localhost:8888/drupal
So, the image path will be like this ...
<img alt="" src="/drupal/sites/all/themes/myancast/images/ios.png">
This image appears in the last few days ago. Today, I run the site and that image disappear immediately and got 403 error.
Failed to load resource: the server responded with a status of 403 (Forbidden).
I'm trying to find the solution the whole day. But, I still cannot solve.
Can anyone help me please ?
Add global $base_url in your code and use like below
<img alt="" class="img-responsive" src="<?php echo $base_url.'/'.path_to_theme(); ?>/images/provider-1.jpg" />
did you try this ?
<img alt="" class="img-responsive" src="<?php echo '/'.path_to_theme(); ?>/images/provider-1.jpg" />
try this,
<?php
$imgurl = file_create_url(path_to_theme().'/images/provider-1.jpg');
?>
<img alt="" class="img-responsive" src="<?php echo $imgurl ?>"/>
Hi , I have placed in my php to get the image file from the folder, but it is giving me a error in the source saying
Warning: Division by zero in
My code is :
<img src="<?php echo get_bloginfo('template_directory') /imgs/Logo.png;?>" alt="Logo" class="logo">
It was working for me last week , i forget what I have changed but now can not fix this , can anyone please help?
<img src="<?php echo get_bloginfo('template_directory').'/imgs/Logo.png';?>" alt="Logo" class="logo">
Try this
<img src="<?php echo get_bloginfo('template_directory');?>/imgs/Logo.png" alt="Logo" class="logo">
<li><a href='#'>Core Transformation</a>
<img alt='arrow' src=**'http://localhost/wordpress1/wp-content/themes/twentytwelve/images/header-triangle.png'** /></li>
<li><a href=**'#'**>LINKS</a></li>
<li><a href=**'#'**>Contact Us</a></li>
How can I replace the src and href using the site_url() function?
You can use the following ways :
<img src="<?php bloginfo('template_url'); ?>/images/image.jpg" />
<img src="<?php echo get_template_directory_uri();?>/images/image.jpg" />
<img src="<?php home_url();?>/images/image.jpg" />
<img src="<?php echo site_url();?>/images/image.jpg"/>
you can do it same for href
More details refer codex
<img src="<?php echo site_url();?>/images/image.jpg"/>
or a better option would be:
<img src="<?php bloginfo('template_url'); ?>/images/image.jpg" />
You can do similarly for href
site_url() is used to append text on url.. so if you want to navigate to your directory and fetch something you can use it like this..
site_url('/images/default.jpg');
you can replace your src with following way:
<img src="<?php bloginfo('template_url'); ?>/images/yourimagename.extension" />
for more information about wordpress go to http://www.wpbeginner.com/wp-themes/wordpress-theme-cheat-sheet-for-beginners
that will help you more in future.
Still you getting any issues with that,then comment it.
<img src="…/<?php echo "$ArtFilePath"; ?>">
gives me this. It’s actually the one I want only without the …
http://markdinwiddie.com/PHP2012/.../artwork/Drawings/Boy.jpg
<img src="../<?php echo "$ArtFilePath"; ?>">
give me this
http://markdinwiddie.com/artwork/Drawings/Boy.jpg
<img src="/../<?php echo "$ArtFilePath"; ?>">
gives me this
http://markdinwiddie.com/artwork/Drawings/Boy.jpg
and
<img src="/…/<?php echo "$ArtFilePath"; ?>">
gives me this
http://markdinwiddie.com/.../artwork/Drawings/Boy.jpg
What I need is
http://markdinwiddie.com/PHP2012/artwork/Drawings/Boy.jpg
Who knows the order of dots and slashes?
Since $artFilePath == "artwork/Drawings/Boy.jpg", you want either:
Relative urls
Provided your php file is within /PHP2012/ this will work. It will even work if you rename the directory
<img src="<?php echo $ArtFilePath ?>" />
Which outputs
<img src="artwork/Drawings/Boy.jpg" />
Absolute urls
<img src="/PHP2012/<?php echo $ArtFilePath ?>" />
Which outputs
<img src="/PHP2012/artwork/Drawings/Boy.jpg" />
if the webpage is within the PHP2012 folder: http://markdinwiddie.com/PHP2012/
and your image is in artwork/Drawings/Boy.jpg within the PHP2012 folder
can't you just do <img src="<?php echo "$ArtFilePath"; ?>">
Not even sure if methods is the correct terminology...
Here is the original working code:
<a href="<?php bloginfo('url'); ?>">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/logo.png" alt="Polished Logo" id="logo"/></a>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/separator.png" width="2" height="59" alt="Line" class="logo_line"/>
<p id="logo_title"><?php bloginfo('description'); ?></p>
I wanted it to only execute on the homepage, so I wrote this:
<?
if ( $_SERVER["REQUEST_URI"] == '/' ){
echo '<a href="'.bloginfo('url').'">
<img src="'.bloginfo('stylesheet_directory').'/images/logo.png" alt="Polished Logo" id="logo"/></a>
<img src="'.bloginfo('stylesheet_directory').'/images/separator.png" width="2" height="59" alt="Line" class="logo_line"/>
<p id="logo_title">'.bloginfo('description').'</p>';
}
?>
But it outputs the bloginfo() and the other declarations completely outside the html tags I have created. For instance, with bloginfo('stylesheet_directory') it will display the directory outside the IMG tags I created.
Any ideas? Apparently my syntax isn't correct or something....
bloginfo function directly echoes the output. In this case you should use get_bloginfo to add the returned value to the string and echo the complete string. I believe this will work
<?php
if ( $_SERVER["REQUEST_URI"] == '/' ) {
echo '<a href="'.get_bloginfo('url').'">
<img src="'.get_bloginfo('stylesheet_directory').'/images/logo.png" alt="Polished Logo" id="logo"/></a>
<img src="'.get_bloginfo('stylesheet_directory').'/images/separator.png" width="2" height="59" alt="Line" class="logo_line"/>
<p id="logo_title">'.get_bloginfo('description').'</p>';
}
?>
Here is a better alternative:
<?php if ( $_SERVER["REQUEST_URI"] == '/' ) { ?>
<a href="<?php bloginfo('url') ?>">
<img src="<?php bloginfo('stylesheet_directory') ?>/images/logo.png" alt="Polished Logo" id="logo"/>
</a>
<img src="<?php bloginfo('stylesheet_directory') ?>/images/separator.png" width="2" height="59" alt="Line" class="logo_line"/>
<p id="logo_title"><?php bloginfo('description') ?></p>
<?php } ?>
I also suggest using the is_home() function provided by wordpress to check for the homepage instead of checking the $_SERVER['REQUEST_URI'] value.
bloginfo() outputs data with echo and returns nothing, so instead of trying to concatenate everything, just output in sequence, e.g.
echo '<a href="';
bloginfo('url');
echo '"><img src="';
bloginfo('stylesheet_directory');
//etc...
Ugly I know, but see answer by Nithesh for a possible alternative.
if you want to get the template path without auto echoing it by the bloginfo() function use:
get_bloginfo( 'stylesheet_directory', 'display' )