top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to disable JavaScript for mobile view in Wordpress?

0 votes
538 views

I want to disable my extra JavaScript functions of my WordPress website when it viewing in small screens like mobile, because speed of my website is very slow in small screens. Can anyone help me how I disable my extra JavaScript for mobile view?

posted Jun 1, 2017 by Sumanta Hazra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

You can use wordpress wp_is_mobile() function. Like this you can use:

<?php
if ( wp_is_mobile() ) {
    /* Display and echo mobile specific stuff here */
}
?>
answer Jun 8, 2017 by Ram Jana
Similar Questions
0 votes

I am a beginner in WordPress. I have already set up my WordPress-Theme for Desktop and I am happy with it and now I have tried to make some tweaks in the theme for the mobile device, but when I open my page on my mobile phone, those changes don't show up.

I have tried to make the theme for mobile device by overwriting the CSS-Selectors with the following:

@media (max-width: 700px) {
    …
}

But this is does not work on mobile device. How can I solve this? Can anybody help me?

0 votes

I want to parse xml for getting element with same attribute and display it into my wordpress post using shortcode by php.
I create a xml file called emp_test.xml

<?xml version="1.0" encoding="utf-8"?>
<all_emp>
<emp_detail>
    <emp emp_name="john"><img>john_1.jpg</img></emp>
    <emp emp_name="john"><img>john_2.jpg</img></emp>
    <emp emp_name="john"><img>john_3.jpg</img></emp>
    <emp emp_name="marry"><img>marry_1.jpg</img></emp>
    <emp emp_name="marry"><img>marry_2.jpg</img></emp>
    <emp emp_name="david"><img>david_1.jpg</img></emp>
</emp_detail>
</all_emp>

I create shortcode in functions.php to get all img has attribute is john:

function create_shortcode_empimg() {
$url = 'https://.../emp_test.xml';
$xml = simplexml_load_file("$url") or die("Error: Cannot create object");
foreach ($xml->xpath("//*[@emp_name='john']/img") as $node)
{
    $img = (string) $node;
    return $img;
}
}
add_shortcode( 'empimg_shortcode', 'create_shortcode_empimg' );

I use this shortcode into my wordpress post.

But, the reult is comming like this:

john_1.jpg

How to get all img has attribute is john like?

john_1.jpg
john_2.jpg
john_3.jpg

Anyone's help is appreciated.

0 votes

I want to create a shortcode for category title in wordpress to display the category name, and I found this code:

function categories_list_func( $atts ){
 $categories = get_the_category();

     if($categories) {
        foreach($categories as $category) {
            $output .= '<li class="cat-' . $category->cat_ID . '"><a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "Read more posts from : %s" ), $category->name ) ) . '">'.$category->cat_name.'</a></li>';
        }
        $second_output = trim($output);
      }
      $return_string = '<h4>'.__( "Categories :", "my_site").'</h4><div class="overflow"><ul class="post-categories">' . $second_output . '</ul></div>';

 return $return_string;

} // END Categories
add_shortcode( 'categories-list', 'categories_list_func' );

Can anybody help me how I create this shortcode?

...