Multiple Checkbox Control for WP Customizer

Since WordPress.org theme review team asked all theme authors to implement the Customizer for their theme options, how to leverage the core customizer controls is important for any theme authors. Core provides several built-in control types: text checkbox (it’s single checkbox) textarea radio (pass a keyed array of values => labels to the choices argument) … Continue reading “Multiple Checkbox Control for WP Customizer”

Clean Up wp_head

WordPress will by default output quite a lot of unnecessary stuff on the document header with the wp_head() function. Let’s start removing them. Put following codes to your functions.php, a recommended way is to hook to the after_setup_theme action. View the code on Gist. Comment line by line. L1: The RSD(Really Simple Discovery) is an … Continue reading “Clean Up wp_head”

How to fix “pagination not working” in custom query

By default, in any given context, WordPress uses the main query to determine pagination. The main query object is stored in the $wp_query global, which is also used to output the main query loop. Pagination template tags, including previous_posts_link(), next_posts_link(), posts_nav_link(), and paginate_links(), base their output on the main query object, $wp_query. That main query … Continue reading “How to fix “pagination not working” in custom query”

Get the input content of TinyMCE editor

I am recently working on a project that enables users to submit content from frontend. Since I am using wp_editor() to display the editor, I find it a little bit of confused how to correctly save the input content. StackExchange user Sam posted a solution in a thread. It just works perfect. WordPress keeps track … Continue reading “Get the input content of TinyMCE editor”

Assign a color to a category in WordPress

In a previous post I’ve showed how to add a like button in category/tag/etc archive page with the term meta function introduced in WordPress 4.4. I’ve also had another post about how to add additional fields to Category and Taxonomy. Since it’s posted before WordPress 4.4, the data of custom fields are saved using a … Continue reading “Assign a color to a category in WordPress”

Add Custom Post States to WordPress posts and pages

You may find that in the post list tables there are some posts/pages title followed by certain conditions. For example, scheduled posts, draft posts and so on they are all flagged with corresponding states. This also applies to pages. On a recent project, I’d like to add a custom state to all pages if they … Continue reading “Add Custom Post States to WordPress posts and pages”

Redirecting 404 Error Pages to any page in WordPress

404’s are part of every website. In WordPress, most themes has a 404.php template file and WordPress will automatically use that page if a Page Not Found error occurs. In this post, I’ll show you how to redirect 404 page to any page in WordPress. Method #1 Open your 404.php file in your theme’s folder. … Continue reading “Redirecting 404 Error Pages to any page in WordPress”