How to set posts redirect to a new domain

Linux, snippet, Uncategorized, Wordpress, , , , , Leave a comment

I’m moving out a blog to a new domain, and redirect all posts specifically to a new domain.

should go to

Apache Server

On Apache that allows .htaccess, you can add this line on top of the file:

RewriteEngine on
RewriteRule ^(.*)$ http://www.newsite.COM/$1 [R=301,L]

Nginx Server

On Nginx, add this line on server block configuration file:

server {
return 301$request_uri;

Reload or restart Nginx for the change to take effect.


Adjust WordPress JPEG Resize Quality

snippet, Wordpress, , Leave a comment

Got your latest images pixelated after uploading it to WordPress? Yes, that could be irritating especially on Photography sites.  WordPress has a function to adjust the level of the image quality, as described on Developer Code Reference.

Simply put this small code to your functions.php

function update_jpeg_quality( $quality, $context ) {
	return 100;
add_filter( 'jpeg_quality', 'update_jpeg_quality' );

Adjust return number to set the level of compression.

100 = No Compression applied. Change it moderate compression about 80. Anything below 80 will make your images looks pixelated but produced a minimum of file size.

Add Custom Size Image to Media Popup in WordPress

PHP, snippet, Wordpress, , Leave a comment

In WordPres 4.5, my old function to add a custom size to media uploader seems not working anymore. But I found that new way to add custom size image is a lot simpler using image_size_names_choose filter.

Basically when you create your own image sizes using the add_image_size function:

function add_news_thumb() {
    add_image_size( 'news', 800, 300, TRUE );
    add_image_size( 'news-detail', 1500, 600, TRUE );
add_action( 'after_setup_theme', 'add_news_thumb' );

you can just add the new sizes to image_size_names_choose:

function added_custom_size( $sizes ) {
  return array_merge( $sizes, array(
	'news' => __( 'News Thumbnail' ), 
	'news-detail' => __( 'News Detail ' ),
  ) );
add_filter( 'image_size_names_choose', 'added_custom_size' );

Screen Shot 2016-06-06 at 4.36.51 PM