How to Use WebP Images in WordPress?

Webp images are not allowed to WordPress media library with default setting. To enable the .webp format use the following code block in your functions.php file inside the theme folder.

/* Enable webp image support for media */
function webp_upload_mimes( $existing_mimes ) {
	// add webp to the list of mime types
	$existing_mimes['webp'] = 'image/webp';

	// return the array back to the function with our added mime type
	return $existing_mimes;
add_filter( 'mime_types', 'webp_upload_mimes' );

/* Enable preview / thumbnail for webp image files. */
function webp_is_displayable($result, $path) {
    if ($result === false) {
        $displayable_image_types = array( IMAGETYPE_WEBP );
        $info = @getimagesize( $path );

        if (empty($info)) {
            $result = false;
        } elseif (!in_array($info[2], $displayable_image_types)) {
            $result = false;
        } else {
            $result = true;

    return $result;
add_filter('file_is_displayable_image', 'webp_is_displayable', 10, 2);

How to convert any full URL path to relative to WordPress installation (root)

If you want to make a URL relative from the WordPress root, you can use the following WordPress function.


$full_url = "";

$relative_to_wordpress = wp_make_link_relative($full_url);

echo $relative_to_wordpress;


Result: /how-to-programmatically-add-a-wordpress-admin-user-using-functions-php/

That’s all! Happy coding!

How to programmatically add a WordPress admin user using functions.php

Step 1:
Open your theme’s functions.php using a editor.

Step 2:
Paste the following code at the bottom of the functions.php (need to remove once the user is added)

add_action('init', 'create_my_custom_admin_user');

function create_my_custom_admin_user() {
    $username = 'username123';
    $password = 'pasword123';
    $email = '';

    if (username_exists($username) == null && email_exists($email) == false) {

        // Create the new user
        $user_id = wp_create_user($username, $password, $email);

        // Get current user object
        $user = get_user_by('id', $user_id);

        // Remove role

        // Add role

Step 3:
Save the functions.php file and run the site once.

Step 4:
Go to the site’s login page (wp-login.php) and login with the username and password that are used on the functions.php. You should be able to login and see the dashboard.

Note: If the username or email already exists in the dashboard, you will not be able to login and in that case you may have to username and/or password.

Step 5:
Please remove the code block and save the functions.php once the user is added.