I am trying to use the get_option() function in Wordpress to set the SRC of an image in a theme file. The file is index.php, and represents the homepage.
The current image code is:
<img class="outside-collage-image" <?php echo 'src="'.get_option('article-image-1').'"'; ?>>
However, the image doesn't display, and when I inspect it, it simply says src(unknown) where it should have the proper SRC
I have tried a myriad of fixes, including leaving the SRC out of the php area and simply calling the function, but it doesn't seem to work.
The oddest part is, if I put on the page <p><?php echo 'src="'.get_option('article-image-1').'"'; ?></p> to check the output, it outputs into the <p> the proper code: src="http://image-site.com/my-image.jpg" (obviously the link to the image is fake, but the point is, it's a valid link.)
Any idea what could be causing this?
You can try this to get the image article-image-1.jpg in your root.
<img class="outside-collage-image" src="<?php echo get_site_url().'/article-image-1.jpg'; ?>">
It turns out that I screwed up, and the above function works just fine. I was simply applying it to the wrong image, and didn't realize that until looking at it a day later, when it wasn't 1:30 AM and I wasn't so tired. Thanks to all that answered.
headdesk
Related
I'm trying to use a variable in a .php file to choose img src.
Here's my attempt:
<?php echo "<img src=\"$ICON\">"; ?>
or
<img src="<?php echo $ICON; ?>"/>
Neither have worked, is there anything obviously wrong? There's nothing displaying, not even the code, when I render the page.
Any guidance would be much appreciated, especially a correct implementation of the above. Sorry for poor code, only looked at these languages since yesterday.
I have this problem, i have this script in php that creates a image on the fly, the problem is that the outputted image on the browser is allright, but i need to change it's name.
Ex: Index.php
<?php $url = "http://www.somesite.com/cls/image_scrc?_aaa=qJ7VgSxWBLG3FfNQVB%2BKI58kfHQulPHZLuLYaZAG6Tk%3D&_ab=3ctGTf547wdsAGjY%2F5FASE%2BpBnbQEAcrhbJzCHQ7mGs%3D&_acb=89e62acf3b4d254abf0c3ab30d6ebb33" ?>
<img src="<?php echo $url ?>" />
The image_scrc.php is the file that creates the image, and as you can see i have several data that is passed by the get method.
In the image_scrc.php i have tryed
header('Content-type: image/jpg');
header('Content-Disposition:inline; filename="'.$random_name_jpeg.'"');
but the html link is is always appearing like this
http://www.somesite.com/cls/image_scrc?_aaa=qJ7VgSxWBLG3FfNQVB%2BKI58kfHQulPHZLuLYaZAG6Tk%3D&_ab=3ctGTf547wdsAGjY%2F5FASE%2BpBnbQEAcrhbJzCHQ7mGs%3D&_acb=89e62acf3b4d254abf0c3ab30d6ebb33
if i select the image on browser and then select copy image link it copies just like this also.
however, when I save the image it assumes the random_name.jpg, but only on save!
i've tried everything, even htaccess rules but nothing seems to work !!
it's this possible to acomplish? transform this
http://www.somesite.com/cls/image_scrc?_aaa=qJ7VgSxWBLG3FfNQVB%2BKI58kfHQulPHZLuLYaZAG6Tk%3D&_ab=3ctGTf547wdsAGjY%2F5FASE%2BpBnbQEAcrhbJzCHQ7mGs%3D&_acb=89e62acf3b4d254abf0c3ab30d6ebb33
to this
http://www.somesite.com/cls/random_name.jpg
i cant have the image on the server side! and must be displayed on the fly
Thanks in advance.
I'm completely new to PHP and I'm writing a page which displays some images from my hard drive.
I've tried different syntaxes and none of them worked out for me ...
I've tested
echo '<img src="/var/www/netbeans/PhpProject2/Plate.jpg" alt ="Test" />';
and It didn't show anything for me .... I've tested this code Also and it didn't worked for me too, I've attached My monitor screen page below. as you can see it seems that my images are not found. I've pasted every address of my images in my browser separately and I was able to see them but when I add them in src argument of img function I'm not able to see them!
What do you think might be the source of problem .... I need to work on a project which needs to be fast enough in working with images.. what do you think I should use ? is "
Try to remove the /var/www. Path should be the http path not the file physical path.
echo '<img src="/netbeans/PhpProject2/Plate.jpg" alt ="Test" />';
I am trying to call images in this function, but they all come up as question marks. Could anyone tell me what I did wrong?
if(!$currentvotes) $currentvotes = 0;
echo '<div class="vote vote'.$id.'"><span>'.$currentvotes.'</span>';
if($user_ID && !$alreadyVoted) echo '<br /><a post="'.$id.'" user="'.$user_ID.'"><img src="/images/thumbsup.png" WIDTH=25 HEIGHT=25></a>';
if($user_ID && $alreadyVoted) echo '<br /><span class="voted"><img src="/images/thumbsup.png" WIDTH=25 HEIGHT=25></span>';
echo '</div>';
if(!$user_ID) echo '<div class="signup"><p><a style="color:#4ec1f3;" href="'.get_bloginfo('url').'/wp-login.php?action=register"><img src="/images/thumbsup.png" WIDTH=25 HEIGHT=25></p></div>';
}
I am trying to call images in this function
As in the comments:
You can't 'call' an image. You can call functions, methods,
procedures, code but images are data and can't be 'called'. – Patashu
[...] they all come up as question marks
Right click on those question marks: choose "open image in new window". You should see a new page with a 404 error. Look at the link of that page: that's the path where your image is supposed to be (if you're getting a 404 error it simply means they are not there). Create the folder images and upload the file thumbsup.png. Now reload the page.
I suppose the path you are using has to be absolute eg (http://.../images/myimage.jpg) instead /images/myimage.jpg. This is common issue when you write custom code (don't use standard framework) and use .htaccess to rewrite urls.
You can set basepath as constant so you can easy change it if you switch domains.
define("BASE_PATH", "http://mydomain.com");
and then in code use it:
BASE_PATH."/images/myimage.jpg"
Or use base tag in your head in html
<base href="http://www.yourdomain" target="_blank">
And as Saturnix said in his answer you should have folder named "images" and filename you put in src.
If an image can't be found in the location you specify in your HTML, the browser will display a broken image link marker, maybe like one of these;
Chrome
IE10
Firefox 10
Each browser has its own marker. Maybe your browser uses a question mark to indicate a broken image link.
I have a problem in my wordpress theme.
The thumbnail doesn't appear on every post.
I have a website with games and every game has a thumbnail (image) . But now the image doesn't appear. When I try to see the image I get this:
Invalid src mime type:
The problematic code is:
<img src="<?php bloginfo('template_url');?>/thumb.php?src=<?=$thumb;?>&w=183&h=140&zc=1" class="thumb" alt="<?php the_title(); ?>" />
What might be wrong?
Browsing to your site I saw what the issue is. If you look at your code, it's being generated like this:
<img src="http://jocuri2k.com/wp-content/themes/Games/thumb.php?src=<?=$thumb?>... ?>
It seems that your PHP parser isn't picking up the php in the tag. Try using this instead:
<img src="http://jocuri2k.com/wp-content/themes/Games/thumb.php?src=<?php=$thumb?>... ?>
It's possible your php configuration doesn't allow for "short-tags"
<?
code here
?>
but instead require the full php tags, which are:
<?php
code here
?>
You might be able to override this in your php.ini, but if you don't have access to that, simply use the full php tags and you should be good to go.
<?php echo $thumb; ?>