Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Can i relink an image link for another media query? WordPress

  • SOLVED

Hi! Is it possible to relink an image?

For example, I have a link on a logo image on my site (it goes to willkommen-page), but on my media query for iphone I want that it links to the homepage, so can I somehow relink the image?

This image link should link to another page on an iphone media query...


<div id="div-h-block-3"><a href="http://alpha.restaurant-richard.de/willkommen/"><img class="header-logo aligncenter" title="RESTAURANT-RICHARD" src="http://alpha.restaurant-richard.de/wp-content/uploads/2012/10/RICHARD-s-288.png" alt="Restaurant-Richard" class="logo-center" width="191" height="28" /></a></div>

Answers (2)

2012-10-05

Arnav Joy answers:



you can do it in either of two ways:-

1. Create two sections , section one will run normally and section two will be visible when the site is at iphone. so in both the section you will have logo and that will point to different location.
You can switch to these sections using media query.

2. Install this plugin

http://wordpress.org/extend/plugins/php-browser-detection/

and then try this

<?php
if ( is_iphone($version) ) {
?>
<script>
jQuery(document).ready(function($){
$('#div-h-block-3').find('a').attr('href','<?php echo get_bloginfo("url");?>') ;
});
</script>
<?php
}
?>


klaus dyba comments:

I would like to avoid having another logo with the link on the page so I would like to use the script, but where do i add the old and the new link url into the script?


Arnav Joy comments:

install the plugin and place the script in header.php or footer.php

new url will point to home page of the site

you can change it here

$('#div-h-block-3').find('a').attr('href','<?php echo get_bloginfo("url");?>') ;

like

$('#div-h-block-3').find('a').attr('href','http://yoursite.com') ;


klaus dyba comments:

My header.php looks like this. Where do I have to insert it?


<?php
/* Prevent direct access to this file */
if ( !defined('WP_CONTENT_DIR') )
die('Please do not access this file directly.');

HeadwayDisplay::html_open();

wp_head();

HeadwayDisplay::body_open();


Arnav Joy comments:

try this

<?php

/* Prevent direct access to this file */

if ( !defined('WP_CONTENT_DIR') )

die('Please do not access this file directly.');



HeadwayDisplay::html_open();

if( function_exists('is_iphone') ) :
if ( is_iphone($version) ) :

?>

<script>

jQuery(document).ready(function($){

$('#div-h-block-3').find('a').attr('href','<?php echo get_bloginfo("url");?>') ;

});

</script>

<?php

endif;
endif;

wp_head();



HeadwayDisplay::body_open();





klaus dyba comments:

Unfortunatly it doesnt seems to work. So I think I have to make an extra logo and display none it on the real site...


Arnav Joy comments:

are you checking this on iphone or resizing browser window?


klaus dyba comments:

on iphone. it always goes to the "willkommen" page...


klaus dyba comments:

Sorry I forgot to install the plugin. ;-( but I figured it out with your second suggestion! Thanks!

2012-10-05

Navjot Singh answers:

Check this [[LINK href="http://stackoverflow.com/questions/5624380/change-web-page-content-if-user-is-on-a-mobile-device"]]solution at Stackoverflow[[/LINK]]. You can do something similar like this.