Redirect website with WWW and without WWW using .htaccess


Redirect without WWW 

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.aviweb\.com [NC]
RewriteRule ^(.*)$ http://aviweb.com/$1 [L,R=301]



Redirect with WWW 

RewriteEngine on
RewriteCond %{HTTP_HOST} ^aviweb\.com [NC]
RewriteRule ^(.*)$ http://www.aviweb.com/$1 [L,R=301]


Custom post type redirect in WordPress

add_action( 'template_redirect', 'aviweb_redirect_post_type' );
function aviweb_redirect_post_type() {
	$queried_post_type = get_query_var('post_type');
	if ( is_single() && 'custom_post' ==  $queried_post_type ) {
		$redirection_url = get_site_url() . '/custom_page';
		wp_redirect( $redirection_url, 301 );
	exit;
	}		
}

Get WordPress dynamic URL in JS file

//Include JS file

wp_enqueue_script('js_file', plugins_url('assets/js/js_file.js', __FILE__), array('jquery'), false);
wp_localize_script( 'js_file', 'WPURLS', array(
    'ajax_url' => admin_url( 'admin-ajax.php' )
));
	
// JS file
var url = WPURLS.ajax_url; 

WordPress posts_per_page does not work

Use below code.

$web = array( 'posts_per_page' => 5,
    'orderby' => 'date',
    'order' => 'DESC',
    'no_found_rows' => true,
    'update_post_term_cache' => false,
    'update_post_meta_cache' => false,
    'nopaging' => true,
    'post_type' => 'product'
);
$query = new WP_Query( $web );

Upload file into WordPress

if ( ! function_exists( 'wp_handle_upload' ) )
require_once( ABSPATH . 'wp-admin/includes/file.php' );

$uploadedfile = $_FILES['resume'];
$upload_overrides = array( 'test_form' => false );
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
if ( $movefile ) {
   echo $movefile['url'];
   echo 'Success';
}else{
   echo 'Fail';
}