Top Questions

  • 5.11 Years

    • Category : Php
    • Location : Mohali
    • Posted On : Jul 2, 2016

    When you’re using a sophisticated design, CSS files can quickly become very long, and takes time to load. I have compiled interresting ways of compressing CSS files by using PHP.

    (1.)
    <link rel="stylesheet" type="text/css" media="screen" href="/style.css.php"/>
    Once you successfully rename your css files, edit it and add the following code at the beginning of the file:
    <?php if(extension_loaded('zlib')){ob_start('ob_gzhandler');} header("Content-type: text/css"); ?>
     

    2 Answers

    View More
  • 2.9 Years

    • Category : Html
    • Location : Chandigarh
    • Posted On : Mar 10, 2016
    <html>
    <head>
    <style>
      .js div#preloader { position: fixed; left: 0; top: 0; z-index:99999; width: 100%; height: 100%; overflow: visible; background:#FFFFFF url('images/load.gif') no-repeat center center;background-size:30%;}
    .ui-loader.ui-corner-all.ui-body-a.ui-loader-default {display: none;}
      </style>
    </head>
     <div class="js">
    <body>
    <div id="preloader"></div> 
    </body>
    </div>
    </html>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script>
    /*====================================================== start */
    
    
    jQuery(document).ready(function($) {  
    
    // site preloader -- also uncomment the div in the header and the css style for #preloader
    $(window).load(function(){
      $('#preloader').fadeOut('10000',function(){$(this).remove();});
    });
    });
    /*====================================================== end */
    </script>

     

  • 2.9 Years

    • Category : Htaccess
    • Location : Chandigarh
    • Posted On : Jul 28, 2016

    increase your site speed by adding this code

    <ifModule mod_gzip.c>
    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-javascript.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
    </ifModule>
    # END gzip file compression
    
    FileETag none
    
    # BEGIN gzip file compression
    # Compress HTML, CSS, JavaScript, Text, XML and fonts
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/rss xml
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE application/x-font
    AddOutputFilterByType DEFLATE application/x-font-opentype
    AddOutputFilterByType DEFLATE application/x-font-otf
    AddOutputFilterByType DEFLATE application/x-font-truetype
    AddOutputFilterByType DEFLATE application/x-font-ttf
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/xhtml xml
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE font/opentype
    AddOutputFilterByType DEFLATE font/otf
    AddOutputFilterByType DEFLATE font/ttf
    AddOutputFilterByType DEFLATE image/svg xml
    AddOutputFilterByType DEFLATE image/x-icon
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/xml
    # Remove browser bugs
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    Header append Vary User-Agent
    
    <FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
           ExpiresActive On
           ExpiresDefault "access plus 1 year"
    </FilesMatch>
    
    /********Add below code to header start of site**********/
    <?php ob_start('ob_gzhandler'); ?>
     
  • 2.9 Years

    • Category : Jquery
    • Location : Chandigarh
    • Posted On : Feb 4, 2017

    you can copy text to clipboard and paste where you want

    <button class="btn btn-success" id="copyButton" onclick="copyToClipboard('testing')">Copy</button>
    
    <script type="text/javascript">
    function copyToClipboard(elementId) {
    
      // Create a "hidden" input
      var aux = document.createElement("input");
    
      // Assign it the value of the specified element
      aux.setAttribute("value", elementId);
    
      // Append it to the body
      document.body.appendChild(aux);
    
      // Highlight its content
      aux.select();
    
      // Copy the highlighted text
      document.execCommand("copy");
    
      // Remove it from the body
      document.body.removeChild(aux);
    
    }
    </script>
  • 5.11 Years

    • Category : Wordpress
    • Location : Mohali
    • Posted On : Feb 22, 2018

    This action hook allows you to access data for a new user immediately after they are added to the database. The user id is passed to hook as an argument.

    add_action( 'user_register', 'eddpremium_register_fields_save');
    add_action( 'profile_update', 'eddpremium_register_fields_save');
    
    function eddpremium_register_fields_save($user_id) {
    	$u = new WP_User($user_id);
    
    	// Remove role
    	$u->remove_role( 'subscriber' );
    
    	// Add role
    	$u->add_role( 'author' );
    }
     
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Jan 7, 2016
    if(isset($_GET['mintime']) && isset($_GET['maxtime'])){
        $extraconditionsa = $extraconditionsa ."and TIME_FORMAT (
       str_to_date (
           replace (hour,':',''),'%H%i'),'%H:%i') between '{$_GET['mintime']}' AND '{$_GET['maxtime']}'";
    }
    
    // mysql:How do I check if a column is empty or null in mysql
    SELECT * FROM table_name WHERE NULLIF(some_col, '') IS NULL;

     

  • 5.11 Years

    • Category : Wordpress
    • Location : Mohali
    • Posted On : May 29, 2018

    default WooCommerce if the user clicks on the add to cart button, that item is added to the cart. if you want to add custom add to cart button please remove default "add to cart" button

    // custom template
    <button type="submit" class="custom_cart_button">add to cart</button>
    <script type="text/javascript">
    jQuery(document).ready(function() {
    var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
        jQuery('.custom_cart_button').submit(function(e) {
            jQuery.ajax({
                url: ajaxurl,
                type: "post",
                data: {				
    		action : 'post_product_variations19'
    	    },
                success: function(data) {   
                	console.log(data);
                }
            });
    	return false;
        });
    });
    </script>
    
    
    // function.php
    add_action( 'wp_ajax_nopriv_post_product_variations19', 'post_product_variations_func19' );
    add_action( 'wp_ajax_post_product_variations19', 'post_product_variations_func19' );
    function post_product_variations_func19() {
    
        global $woocommerce;
    
        $product_id = 364; // your product id
    
        $found = false;
    
        //check if product already in cart
        if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
            foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values ) {
                $_product = $values['data'];
                if ( $_product->id == $product_id ) {
                	//$calc_qty = $values['quantity'] < 1 ? 1 : $values['quantity']+1;
                	//$woocommerce->cart->set_quantity( $cart_item_key, $calc_qty, true );
                    $found = true;
                }
            }
            // if product not found, add it
            //if ( ! $found )
                $woocommerce->cart->add_to_cart( $product_id );
        } else {
            // if no products in cart, add it
            $woocommerce->cart->add_to_cart( $product_id );
        }
    	
    wp_die();
    }
  • 5.11 Years

    • Category : Magento
    • Location : Mohali
    • Posted On : Jul 26, 2018

    Customer session does not work except some pages

    Method 1.  To check if customer is logged: (best way)
    Create helper file like Data.php

    how to create custom helper or module https://www.dorcode.com/blog/52/how-to-create-and-use-helpers-in-magento-2
     
    <?php
    namespace Magento\Mytheme\Helper;
    
    class Data extends \Magento\Framework\App\Helper\AbstractHelper
    {
        protected $_customerSession;
        protected $_customerSessionn;
    
        public function __construct(\Magento\Framework\App\Helper\Context $context,
                \Magento\Framework\App\Request\Http $request,
                \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
                \Magento\Customer\Model\SessionFactory $customerSession,
                \Magento\Customer\Model\Session $customerSessionn
            ) 
        {
            $this->request = $request;
            $this->customerRepository = $customerRepository;
            $this->_customerSession = $customerSession;
            $this->_customerSessionn = $customerSessionn;
            parent::__construct($context);
        }
        public function getCustomerName(){
            $customer = $this->_customerSession->create();
            return $customer->getCustomer()->getName();
        }
        public function isLoggedIn()
        {
            return $this->_customerSessionn->isLoggedIn();
        }
    }
    ?>
    
    Call to your template :
    
    <?php
    $myhelper = $this->helper('Magento\Mytheme\Helper\Data');
    $cname=$myhelper->getCustomerName();
    $isLoggedIn=$myhelper->isLoggedIn();
    
    if ($isLoggedIn):
    	   echo 'login';
    else : 
    	  echo 'not login';
    endif;
    ?>
    Method 2. To check the customer is logged or not on any page of the website:
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    
    $customerSession = $objectManager->get('Magento\Customer\Model\Session');
    
    if($customerSession->isLoggedIn()) {
    
       // customer login action
    
    }
     
  • 5.11 Years

    • Category : Php
    • Location : Mohali
    • Posted On : Nov 23, 2017

    There's a bug in Wordpress 4.9, I discovered this temporary super code. I plan on uninstalling it once they fix the bug, but it works great in the meantime!

    global $wpdb;
    $wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE '_transient_files_%' LIMIT 1" );
     
  • 5.11 Years

    • Category : Wordpress
    • Location : Mohali
    • Posted On : Aug 14, 2015

    After wordpress login redirect page but not refresh so please try to add these lines in the top of the your wordpress theme file like header.php or wp-config.php https://www.youtube.com/watch?v=ItTjUrTZ_JE

    <?php
    str = "Hello world. It's a beautiful day.";
    print_r (explode(" "$str));
    ?>
    

    1 Answers

    View More