Posts

Remove slug from custom post type post URLs

Add given functions in your active theme's functions.php
/** * Remove the slug from published post permalinks. Only affect our custom post type, though. */ function gp_remove_cpt_slug( $post_link, $post, $leavename ) { if ( 'race' != $post->post_type || 'publish' != $post->post_status ) { return $post_link; } $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link ); return $post_link; } add_filter( 'post_type_link', 'gp_remove_cpt_slug', 10, 3 );/** * Have WordPress match postname to any of our public post types (post, page, race) * All of our public post types can have /post-name/ as the slug, so they better be unique across all posts * By default, core only accounts for posts and pages where the slug is /post-name/ */ function gp_parse_request_trick( $query ) { // Only noop the main query if ( ! $query->is_main_query() ) return; // Only …

Remove WordPress Redirecting to Nearest Matching URL

WordPress comes with a nifty feature which enables it to navigate to the closest matching URL if the one typed in doesn’t exist. This reduces the chance of a user getting presented with a 404 page if they’ve slightly mistyped a page’s URL.
Yes, the above is great, but what if we want to disable it? On a site recently I needed to do exactly this when I was using URL’s that didn’t relate to pages and, instead, jumped to different parts of a single page site.
The solution was to add the below code to my theme’sfunctions.phpfile:
remove_filter('template_redirect', 'redirect_canonical');

Send email from localhost in php (XAMPP, WAMP, LAMP)

We face trouble sending email from your localhost server XAMPP, WAMP, LAMP. Because When we setup apache in local system it won’t by default setup for SMTP server . So if we want to send email from your localhost you must have to setup SMTP configuration in php.ini file or we have to use external SMTP server. There are lot’s of external SMTP server are available like Gmail, Hotmail, Yahoo etc. They allow to send email by using their SMTP configuration, we only need to configure some parameter in your local configuration or in your phpmailer code.

Change Entry Title of WooCommerce Endpoints in My Accounts Page

One way around changing the entry-title of the WooCommerce custom endpoint is to use the_title filter with the in_the_loop conditional.
Add below code to your active theme's function.php
/*
 * Change the entry title of the endpoints that appear in My Account Page - WooCommerce 2.6
 * Using the_title filter
 */
function wpb_woo_endpoint_title( $title, $id ) {
 if ( is_wc_endpoint_url( 'downloads' ) && in_the_loop() ) { // add your endpoint urls
 $title = "Download MP3s"; // change your entry-title
 }
 elseif ( is_wc_endpoint_url( 'orders' ) && in_the_loop() ) {
 $title = "My Orders";
 }
 elseif ( is_wc_endpoint_url( 'edit-account' ) && in_the_loop() ) {
 $title = "Change My Details";
 }
 return $title;
}
add_filter( 'the_title', 'wpb_woo_endpoint_title', 10, 2 );

For more details visit: https://wpbeaches.com/change-rename-woocommerce-endpoints-accounts-page/

Create multi dimentional unique array for specific code in php

Create multidimensional array unique for any single key index.
My array is like this,
<?php
$details = array(
0 => array("id"=>"1", "name"=>"Mike",    "num"=>"9876543210"),
1 => array("id"=>"2", "name"=>"Carissa", "num"=>"08548596258"),
2 => array("id"=>"1", "name"=>"Mathew",  "num"=>"784581254"),
); ?> 
You can make it unique for any field like id, name or num.

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);elsereturn$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'=>…