How to add an iframe to Wordpress sidebar? - wordpress

I am using the default TwentyEleven theme, and I added the following code to sidebar.php, but it does not work (I get a 310 error)
<iframe src="frame.html" name="test" height="600" width="180"></iframe>
iframe.html is located in /themes/twentyeleven folder, so it should be working (at least on a regular website).
Is it necessary to use some kind of widget plugin in order to get it to work. What can be preventing the iframe from showing up on the website?
Thank you.

You need to hit the file via an http request, not via the local path.
<iframe src="<?php echo ( get_site_url() . '/wp-content/themes/twentyeleven/iframe.html' ); ?>" />

You Should use get_bloginfo('template_directory') before giving path.......
try using
{
<iframe src="<?php echo get_theme_root(); ?>/frame.html" name="test" height="600" width="180"></iframe>
}
Try reading this
http://codex.wordpress.org/Function_Reference/get_theme_root

Related

Is possible to dynamic path in php files for assets in webpack wordpress development?

I have a theme wordpress development folder (theme/resources/assets) for development and theme/assets for production. When I create header.php and add:
img src=”?php echo get_template_directory_uri();
?>/assets/images/code.png”
In development mode, images don't show up. It works only after build. In dev mode, the path must be /resources/assets/images/code.png
How I can fix that? How I can dynamically change paths in Wordpress PHP files? Is it possible?
You probably should fix the code from
img src=”?php echo get_template_directory_uri();
?>/assets/images/code.png”
To:
<img src="<?php echo get_template_directory_uri();?>/assets/images/code.png" />
For detecting the environment, you may use the built-in WP_DEBUG constant and adjust the path as necessary:
<img src="<?php
echo get_template_directory_uri() . (WP_DEBUG ? '/resources' : '');
?>/assets/images/code.png" />
You could use site URL to check whether it's production or development site and return assets URL based on that:
<?php
$site_url = get_site_url();
if($site_url == 'http://http://stage.example.com'){
// Staging site assets url
$assets_url = get_template_directory_uri() . '/resources/assets';
}else{
// Live site assets url
$assets_url = get_template_directory_uri() . '/assets';
}
?>
<img src="<?php echo $assets_url; ?>/images/code.png" />
Same code can be used in different ways by changing the condition, if you have a better way to compare instead of site URL you can change the if statement and the ourput would be the same.

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

Insert logo header.php 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" />

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

Add php element to custom page in Wordpress

I'm trying to customize a wordpress page to include an iframe which give the users a link to there download. We're using wordpress 2.9.2 with the Thesis theme 1.51. I've been trying to use thesis hooks but appears that the php is stripped from the output. Help? Suggested alternatives?
Code from custom_functions.php:
function add_ejunkie_download_link () {
is_page('slug-url-of-page') {
?>
<?php
echo '<iframe src="https://www.e-junkie.com/ecom/rp.php?noredirect=true&client_id=CID&txn_id=' . htmlspecialchars($_GET["txn_id"]) . '" width="100%" frameborder="0" height="50px"></iframe>';
?>
<?php
}
}
remove_action('thesis_hook_custom_template', 'thesis_hook_custom_template');
add_action('thesis_hook_custom_template', 'add_ejunkie_download_link');
Though not as elegant as custom hook in custom_functions.php, Thesis Open Hook WordPress › Thesis OpenHook « WordPress Plugins is an easy way to add hooks with executable code in them.
Why the remove_action call? I really don't think you need it.
The PHP can't be stripped from the output, because it's just that... PHP. It's parsed at runtime, so it's not stripped, it's executed.
I'm guessing you just want to print the iframe when Thesis calls the thesis_hook_custom_template hook?
Have you double checked this hook is actually getting called, and that it's getting called where you expect it to?
Then try simplifying your hooked function with this;
function add_ejunkie_download_link() {
if (is_page('slug-url-of-page')):
?>
<iframe src="https://www.e-junkie.com/ecom/rp.php?noredirect=true&client_id=CID&txn_id=' . htmlspecialchars($_GET["txn_id"]) . '" width="100%" frameborder="0" height="50px"></iframe>
<?php
endif;
}

Resources