0

Hey guys thanks in advance to all, I was wondering if there is way to run a costume php template file only for mobile?

case: I'm using Woo commerce and I want to make a costum template for the single product page, is it possible to execute that template just for mobile via php / js or any other way ?

I don't want to tweak the main template via Css using display: none etc.

thanks to all,

update:

I'v tried this code but it seems to break ant tips:

<?php
    if ( wp_is_mobile() ) {
      <?php wc_get_template( 'layouts/test.php' ); ?>
    }
?>
2
  • Why don't you want to customize the look and feel with CSS? I personally prefer that; if you go with separate templates for mobile I would use a separate domain as well, otherwise you won't be able to use any HTML cache plugins.
    – cybmeta
    Commented Jun 6, 2018 at 8:45
  • Hey sorry for the late reply, first of all thank you. I want to edit it via php because I don't want to many hidden elements on the page as far as I understand this is not good practice. thanks for the tip regarding separate domain and cache didn't' know that
    – Osh
    Commented Jun 7, 2018 at 4:54

1 Answer 1

0

archive product page overwrite into your current active theme. More detail wp_is_mobile()

<?php
// archive product page


if( wp_is_mobile() )
{
    // your costume template path
}else{
    // Woocommerce defult archive page code put into else part
}

?>

Hope is work for you

2
  • Hey @Patel Jignesh thanks and sorry for the late reply. yes it does make things more clear for sure, just one question where this code needs to go inside index.php ?
    – Osh
    Commented Jun 7, 2018 at 4:56
  • Hey I'v tried your tip, but it seems not to work you can see the code I'v used in the update above cheers
    – Osh
    Commented Jun 7, 2018 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.