Meks
Do you know you can try any of our premium WordPress themes for free?Show me the themes
Convert hex color to rgb or rgba using PHP

Convert hex color to rgb or rgba using PHP

99Shares

As far as we know, many of WordPress theme developers use a lot of design options inside their themes, just as we do. Which means that you usually provide color pickers so the users may easily change color settings for their websites.

This usually means that you will need to create dynamic CSS files instead of a hard-coded CSS, so the user’s color changes may apply on the website instantly. As for HTML5/CSS3 standards, hex colors can’t always do all the work so you need to work with RGB or RGBA color codes.

While we have been struggling with this sometimes, we have made a little PHP helper function which converts hex color code string into RGB or even RGBA color. For example, if you want to add opacity to the color of some element  and basically achieve “transparent hex code”.

Convert hex color to rgba – PHP function

Here’s the code:

So far so good! Now we are going to show you how this function can be helpful whilst creating dynamic CSS with a simple example below.

Usage example:

99Shares
Bojan Petrovic

Co-founder and WordPress developer at Meks. He has been involved in the business since 2009. creating themes, plugins and services on top of WordPress, continuously aiming to choose best approaches and work smarter, not harder.

41 comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You don't need to have loads of money to get a world-class WordPress website! All our themes are rated with the highest 5-star rating. Have a look and choose the best one for you.
Meks WordPress Themes
Meks