Posts

Showing posts from January, 2017

Remove Script and Stylesheet Version in Wordpress

Paste below code in the active themes function.php
add_filter('script_loader_src','remove_version'); add_filter('style_loader_src','remove_version'); functionremove_version($src){ global$wp_version; $version_str='?ver='.$wp_version; $version_str_offset=strlen($src)-strlen($version_str); if(substr($src,$version_str_offset)==$version_str) returnsubstr($src,0,$version_str_offset); else return$src; }

Preventing SQL injection in Codeigniter

In codeIgniter ,we no need to use mysql_real_escape_string() function, Codeigniter provides inbuilt functions and libraries to generate SQL queries by using those methods or functions we can avoid SQL injections.
There are three methods to prevent SQL injections in Codeigniter application, they are
1) Escaping Queries
2) Query Binding
3) Active Record Class
1. Preventing SQL injection in Codeigniter using Escaping Query Method Example: $email=$this->input->post('email'); $query='SELECT * FROM subscribers_tbl WHERE user_name='.$this->db->escape($email); $this->db->query($query); 2. Preventing SQL injection in Codeigniter using Query Binding Method Example: $sql="SELECT * FROM subscribers_tbl WHERE status = ? AND email= ?"; $this->db->query($sql,array('active','support@keredari.com)); 3. Preventing SQL injection in Codeigniter using Active Record Class $this->db->get_where('subscribers_tbl',array('status'=>…

Remove paypal checkout on product page in Prestshop

Follow below steps to fix it:
1. Login into admin panel
2. Click to Position under Module and Serives tab
3. Scroll to displayFooterProduct and unhook it.
That's it.

Add Cross-sells to single product template in Woocommerce

Step 1: get the ids of the cross sell products using the  ‘_crosssell_ids’ meta key.
<?php/* crossells */$crosssell_ids= get_post_meta( get_the_ID(),'_crosssell_ids');$crosssell_ids=$crosssell_ids[0];?>Step 2: Loop through the products by id
<?phpif(count($crosssell_ids)>0){$args=array('post_type'=>'product','posts_per_page'=>10,'post__in'=>$crosssell_ids);$loop=new WP_Query($args);while($loop->have_posts()):$loop->the_post();?><a href='<?php the_permalink();?>'><?php the_post_thumbnail('thumbnail'); the_title();?></a><?phpendwhile;}?>

Display product short description in woocommerce cart or checkout page

In order to add a short description to WooCommerce cart or checkout page, you could use a code, similar to the following:
<?php echo $_product->post->post_excerpt;?>

Get all custom posts by taxonomy

$custom_terms = get_terms('your_custom_taxonomy');foreach($custom_terms as $custom_term){ wp_reset_query(); $args = array('post_type'=>'your_custom_post_type','tax_query'=> array( array('taxonomy'=>'your_custom_taxonomy','field'=>'slug','terms'=> $custom_term->slug,),),); $loop =new WP_Query($args);if($loop->have_posts()){ echo '<h2>'

Rewrites url with custom parameter in WordPress

A bit of research and a solution was at hand, and actually quite simple to do URL Parameter Rewrites in WordPress.For this exercise, let’s assume we want to use the following URL:
www.example.com/gifts/christmas/girl/50  This entails variables for occasion, recipient and price. The non-frienly equivalent URL would look like this
www.example.com/gifts/?occasion=christmas&recipient=girl&price=50 Adding Rewrite Tags First we need to declare the rewrite tags we’d like to use, to make WordPress aware of them. But careful, don’t choose tags that are already in use, otherwise they will get overwritten. These are declared using the add_rewrite_tag function and are best placed inside functions.php.
add_rewrite_tag('%occasion%','([^&]+)'); add_rewrite_tag('%recipient%','([^&]+)'); add_rewrite_tag('%price%','([^&]+)');

fetch youtube video information using api in php

Create a php script to fetch video information where you have to put your youtube video id and parts your going to fetch.
for example:-
https://www.youtube.com/watch?v=7UMNz5T-0VQ
In this URL your youtube video id is showing in red color.
<?php$data=file_get_contents("https://www.googleapis.com/youtube/v3/videos?id=YOUTUBE_VIDEO_ID&key=YOUR_YOUTUBE_APIKEY&part=snippet,contentDetails,statistics,status");$result=json_decode($data,true);echo"<pre>";print_r($result);?>

import excel file into mysql using php

With the help of php we can easily import our excel or csv file data in our Mysql database.
Method-1: Import excel data using php script $handle=fopen("BooksList.csv","r");while(($data=fgetcsv($handle))!==FALSE){$num=count($data);$row;echo"INSERT into importing(text,number)values('$data[0]','$data[1]')";echo"<br>";} Method-2: $handle=fopen("BooksList.csv","r");$fields=array('category','datatype','date','value');$table='test';$sql_query="INSERT INTO $table(".implode(',',$fields).") VALUES(";while(($data=fgetcsv($handle))!==FALSE){foreach($data

Set default opened JQuery tabs other than first

In any case, use the index of the tab you want to open, not the href value; i.e. if you want to open the 3rd tab use:
$("#tabs").tabs({ active:2}); Check this on Fiddle

Select every other row as male/female from mysql table

To Get the result table from table 'people' as below +-----+--------+-------+ | row | gender | name | +-----+--------+-------+ | 1 | female | Lisa | | 2 | male | Greg | | 3 | female | Mary | | 4 | male | John | | 5 | female | Jenny | +-----+--------+-------+Follow the below querySELECT*FROM(SELECT people.*,IF(gender=0,@mr:=@mr+1,@fr:=@fr+1)AS rank FROM people,(SELECT@mr:=0,@fr:=0) initvars ) tmp ORDERBY rank ASC, gender ASC;