Disable “Install the WooThemes updater plugin to get updates”

Here’s a single line code which allows you to get rid of annoying WooCommerce admin notices i.e “Install the WooThemes updater plugin to get updates for your WooThemes plugins”.

All you need to do is copy the following code snippet and paste it inside your functions.php file located inside your themes directory.

remove_action('admin_notices', 'woothemes_updater_notice');

Something you may not know: How to Hook Into WooCommerce to Trigger Something After an Order is Placed

WordPress Asks for FTP Details While Installing Plugins

When you setup a WordPress on Ubuntu Linux and try to install a new plugin from plugin repository it prompts you for FTP Details.

With a few Google searches I managed to find a solution for this problem. To fix this issue all you need to do is run the following command on your terminal.

sudo chown -R www-data:www-data /[folder-path]/[name-of-your-project-folder]

You can also fix this issue by adding following line to your wp-config.php file.

define('FS_METHOD', 'direct');

See Also: How to Get Featured Image Thumbnail URL Using WP REST API

Top 5 Free Code Editors For Web Developers

Code editors have a really heavy impact on the way developers right code. It plays an important role in reducing the errors and speeding up the coding process. There are tons of code editors out there with amazing features like syntax highlighting, code folding, directory tree view and many more which makes your coding much more fun. Here’s a list of top 5 code editors which I prefer to use.

Notepad++

notepad++

notepad++

Notepad++ is one of the most popular, open source and lightweight code editor available today. Personally, I have used Notepad++ for long time. It is very easy to use and comes with many built in features like Syntax highlighting, code folding etc.

Brackets

brackets.io

brackets.io

Brackets is a free and open source editor from Adobe Systems. It is released under MIT License. It is avaliable for Windows, Linux and Mac operating systems.

Komodo Edit

komodo-edit

komodo-edit

Komodo Edit is a free code editor from ActiveState. It comes with a lots of amazing features like syntax highlighting, directory tree view, code folding and much more.

Atom

atom.io

atom.io

Atom is free and open source text editing application from Github. It is desktop application written in web technologies. It supports a wide variety of languages including PHP, Ruby, JavaScript, Objective-C etc.

Bluefish

bluefish

bluefish

Bluefish is another free code editor application distributed under GPL license. It comes with features like Syntax highlighting, Auto-completion and much more.

How to Display Author’s Gravatar on Single Post in WordPress

Here’s a tiny WordPress code snippet which allows the developers to display Post Author’s Gravatar image on individual post. In this code we are using get_avatar() function.

<?php echo get_avatar( get_the_author_meta( 'ID' ), '80' ); ?>

Where the get_the_author_meta( ‘ID’ ) function will return author ID for the author of current post and 80 is the height and width of image the above code will generate. You can also pass Author’s email address as first parameter instead of Author’s ID.

Useful Read: How to Change Author URL Base in WordPress

Remove Author From Recent Comments Widget

By Default, WordPress recent comment widget displays the comment author name and the title of post where the comment was posted. But, this widget doesn’t come with an option in dashboard to remove comment author name from the widget.

However, you can easily fix this issue by adding a small amount of code to your functions.php file located inside your theme directory.

function ccw_remove_comment_author( $array ) {
	global $post;
	$array['user_id'] = !$post->post_author;
	return $array;
}
add_action( 'widget_comments_args', 'ccw_remove_comment_author' );

Read Also : Remove Pingbacks from Recent Comments Widget

How to Add REST API Support to WordPress Custom Post Types

In this tutorials, we are going to add WP REST API support to custom post types in our WordPress application.

Adding REST API support while creating custom post type:

While registering a custom post type, you want to make it compatible with REST API, you need add few additional arguments to the register_post_type function. The three arguments you need to pass are as follows;

  1. show_in_rest (Default: False) – Setting this argument to true will make your post type available to REST API.
  2. rest_base (Default: Post type’s name) – The base slug of the URL which will be used to access via REST API.
  3. rest_controller_class (Default: WP_REST_Posts_Controller ) – Specify a custom controller, which should be a subclass of WP_REST_Controller.

For example, I need to create a custom post type “Movie” with REST API support, my code will look something like this,

add_action( 'init', 'ccw_register_movies_post_type' );
function ccw_register_movies_post_type() {
	$labels = array(
	    'name'               => _x( 'Movies', 'post type general name', 'your-plugin-textdomain' ),
	    'singular_name'      => _x( 'Movie', 'post type singular name', 'your-plugin-textdomain' ),
	    'menu_name'          => _x( 'Movies', 'admin menu', 'your-plugin-textdomain' ),
	    'name_admin_bar'     => _x( 'Movie', 'add new on admin bar', 'your-plugin-textdomain' ),
	    'add_new'            => _x( 'Add New', 'book', 'your-plugin-textdomain' ),
	    'add_new_item'       => __( 'Add New Movie', 'your-plugin-textdomain' ),
	    'new_item'           => __( 'New Movie', 'your-plugin-textdomain' ),
	    'edit_item'          => __( 'Edit Movie', 'your-plugin-textdomain' ),
	    'view_item'          => __( 'View Movie', 'your-plugin-textdomain' ),
	    'all_items'          => __( 'All Movies', 'your-plugin-textdomain' ),
	    'search_items'       => __( 'Search Movies', 'your-plugin-textdomain' ),
	    'parent_item_colon'  => __( 'Parent Movies:', 'your-plugin-textdomain' ),
	    'not_found'          => __( 'No movies found.', 'your-plugin-textdomain' ),
	    'not_found_in_trash' => __( 'No movies found in Trash.', 'your-plugin-textdomain' )
	);

    $args = array(
        'labels'             => $labels,
        'description'        => __( 'Description.', 'textdomain' ),
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'movie' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => null,
        'show_in_rest'       => true,
        'rest_base'          => 'movie',
        'rest_controller_class' => 'WP_REST_Posts_Controller',
        'supports'           => array( 'title', 'editor', 'excerpt', 'thumbnail', 'author', 'comments' )
    );
    register_post_type( 'movie', $args );
}

Adding REST API support to existing custom post type:

Sometimes you may want to add REST API support to a custom post type which is already registered, for example a custom post type which belongs to a theme. In this scenario, you can use global $wp_post_types to perform this task.

The example code for adding REST API support to an existing post type is as follows,

add_action( 'init', 'ccw_rest_apr_support_custom_post_type', 25 );
function ccw_rest_apr_support_custom_post_type() {
	global $wp_post_types;
	$post_type = 'movie';
	if( isset( $wp_post_types[ $post_type ] ) ) {
		$wp_post_types[$post_type]->show_in_rest = true;
		$wp_post_types[$post_type]->rest_base = $post_type;
		$wp_post_types[$post_type]->rest_controller_class = 'WP_REST_Posts_Controller';
	}
}

Read Also: How to Get Featured Image Thumbnail URL Using WP REST API?

How to Get Featured Image Thumbnail URL Using WP REST API

By default, WordPress REST API only returns featured image ID in form of featured_media field. However you can easily resolve this issue by adding a small amount of code to your functions.php file located inside root of your theme directory.

To get featured image URL in JSON response, use the following code.

add_action( 'rest_api_init', 'ccw_insert_thumbnail_url' );
function ccw_insert_thumbnail_url() {
    register_rest_field( 'post',
        'ccw_thumbnail',
        array(
            'get_callback'    => 'ccw_get_thumbnail_url',
            'update_callback' => null,
            'schema'          => null,
        )
    );
}

function ccw_get_thumbnail_url($post){
	if(has_post_thumbnail($post['id'])){
		$imgArray = wp_get_attachment_image_src( get_post_thumbnail_id( $post['id'] ), 'full' );
		$imgURL = $imgArray[0];
		return $imgURL;
	}else{
		return false;	
	}
}

The name of the field in the json response will be ccw_thumbnail. You can change second parameter of wp_get_attachment_image_src function to get the URL of image with a different image size.

Read Also : How to Add Active Class to Current Menu Item in WordPress

How to Add Categories and Tags for WordPress Pages

By default, WordPress doesn’t associate any taxonomy with pages. However, you can easily add default tag and category taxonomies to pages.

Read Also: Applying Categories, Tags and Custom Taxonomies to Media Attachments

Paste the following code into your functions.php file to add categories and tags to WordPress pages.

function ccw_add_category_and_tag_to_pages() {
	//add tags to pages
	register_taxonomy_for_object_type( 'post_tag', 'page' );
	//add categories to pages
	register_taxonomy_for_object_type( 'category', 'page' );
}
add_action( 'init', 'ccw_add_category_and_tag_to_pages' );

We are using register_taxonomy_for_object_type function to perform this task.

How to Embed Facebook Status in WordPress

Facebook is the largest social networking website in the world, which has more than 1 billion active users across the globe.  Millions of exciting messages, photo and news shared on Facebook everyday.

Facebook allows you to embed this information directly into your website.

In this post, we are going to embed a Facebook status in out WordPress blog post. To embed a status into the blog post, follow the steps given below.

Laravel Tip : Rendering a View to a String

1. Click the date or time link which will take you to that page of that specific status

How to Embed Facebook Status Posts in WordPress

How to Embed Facebook Status Posts in WordPress

2. Copy the URL from the address bar.

How to Embed Facebook Status Posts in WordPress

How to Embed Facebook Status Posts in WordPress

3. Paste the URL inside you post editor

How to Embed Facebook Status Posts in WordPress

How to Embed Facebook Status Posts in WordPress

And that’s it.

Here’s an example of embedded status in WordPress blog post,

https://www.facebook.com/coffeecupweb/posts/1596784437264447