Tagged: ,

Viewing 18 posts - 1 through 18 (of 18 total)
  • Author
    Posts
  • #197173

    i need to include a php mobile detection detection script on the home page of my site, but not in the header or footer (doesn’t need to be on every page, just the home page. I tried adding it to a Text Box but it strips the code out.

    <?php
    
    if(isset($_GET['nomobile'])){
       echo "";
    } else {
       echo "<script src='http://mysite.com/custom/detectmobilebrowser.js'></script>";
    }
    
    ?>
    #197243

    Hi Tech!

    You can’t add PHP code in a Page/Post content, put in the header but wrap it inside this conditional tag:

    <?php
    
    if(is_home()){
    	if(isset($_GET['nomobile'])){
    	   echo "";
    	} else {
    	   echo "<script src='http://mysite.com/custom/detectmobilebrowser.js'></script>";
    	}
    }
    
    ?>

    That way that code will only run in the home page.

    Best regards,
    Josue

    #197309

    what am i doing wrong? in a text box i added, didn’ t go into the Visual View and just hit save. it took this

    <?php
    if(is_home()){
    	if(isset($_GET['nomobile'])){
    	   echo "";
    	} else {
    	   echo "<script src='http://mysite.com/custom/detectmobilebrowser.js'></script>";
    	}
    }
    ?>

    and it comments out the php and returns

    <!--?php<br /-->if(is_home()){
    if(isset($_GET['nomobile'])){
    echo "";
    } else {
    echo "<script type="text/javascript" src="http://mysite.com/custom/detectmobilebrowser.js"></script>";
    }
    }
    ?>
    #197322

    You can’t add PHP code in a Page/Post content (Text box), my recommendation was to put it in the header.php file.

    As a side note, if you insist in putting the code in the actual Page you can do it, but you’d need to rely on a plugin: http://wordpress.org/plugins/insert-php/

    Cheers!
    Josue

    #197343
    This reply has been marked as private.
    #197346

    Did it work?

    Regards,
    Josue

    #197348
    This reply has been marked as private.
    #197399
    This reply has been marked as private.
    #197418

    Hey!

    I see, try with this instead:

    <?php
    if(is_home() && isset($_GET['nomobile']){
       echo "";
    } else {
       echo "<script src='http://lapolla.com/custom/detectmobilebrowser.js'></script>";
    }
    ?>

    Regards,
    Josue

    #198163

    thanks josue, although this code will redirect me from teh mobile to the desktop then back to the mobile instantly. I think i may have to tool this a bit or write something more extensive to fit different scenarios. thanks for your help so far

    #198166

    Yes, i think it would be a matter of tweaking and testing, for further information about Conditional Tags refer to this link: http://codex.wordpress.org/Conditional_Tags

    Cheers!
    Josue

    #234035
    This reply has been marked as private.
    #234049

    Hey!

    The script code is appearing in the wrong place (first line):
    view-source:http://www.lapolla.com/

    It should be inside the <head></head> tag.

    Best regards,
    Josue

    #234052
    This reply has been marked as private.
    #234056

    Hey!

    I don’t quite understand how it was working before, where does nomobile come from?

    Best regards,
    Josue

    #234060
    This reply has been marked as private.
    #234255

    Hey!

    Thank you for the question. I hope all is well with you today.

    If you want a mobile redirect for your homepage, please use this plugin: http://wordpress.org/plugins/wp-mobile-detect/faq/

    Refer to this link for more info: https://kriesi.at/support/topic/homepage-redirect-on-mobile-sites/

    Best regards,
    Ismael

    #235953

    thanks ismael & josue! works like a charm. you all can mark this closed

Viewing 18 posts - 1 through 18 (of 18 total)
  • The topic ‘include php detection script not in header’ is closed to new replies.