How toHow to get only the icons URL

If you want to get only the icons URL, you need to copy and paste this function in your functions.php file :

function extract_caticonsurl($string,$return_always_array=FALSE) {
	$myarray = array();
	if (preg_match_all('/<img\s+.*?src=[\"\']?([^\"\' >]*)[\"\']?[^>]*>/i', $string, $matches, PREG_SET_ORDER))  {
		foreach ($matches as $match) {
			$myarray[] = $match[1];
	if ($return_always_array === FALSE && count($myarray) == 1 ) $myarray = array_pop($myarray);
	return $myarray;

And paste this code where you want to get the URL(s) :

$caticons_url = extract_caticonsurl(get_cat_icon('echo=false'));

The extract_caticonsurl function returns an array if there’re several icons, or a string (the URL) if there is only one.

13 thoughts on “How to get only the icons URL

  1. Hello !

    I’m a French student and I have a problem with your plugin. I let you watching my website and you will see the problem. At the right side, you can see some icons and near the name of the categories twice, one is the icon, the second is the name of the category. I really want to delete the name of the category to have only the icon. I think somewhere in the code, we can choose what we want show but i dont find anything. The code of category-icons.php is too difficult to me.

    I hope you answer me, I will be happy.

    Thanks !

  2. Hi Romain.

    I think you’re using the widget to display the categories in the sidebar. So, you need to read this :
    You must use the icons_only=true parameter in the widget, as in the picture.

    Sinon, j’aime bien ton site, et surtout le but pour lequel il est développé, étant moi-même un fan de la région du Var. Si tu as des soucis, n’hésite pas à me recontacter, je t’ai envoyé mon adresse électronique.

  3. Hi,

    This might not be related to the post, however I do seek help with category icons. Have a look on my website: and then you’ll see that I’m using 2 widgets to display posts which all have multiple categories. My question is how can I implement the priority feature within the popular posts and recent posts plugins? You added compatibility for those plugins (Rob Marsh) and I used this code for the output: ‘{caticons} {link}’ (take away the ‘ of course).

    If you know a solution, please let me know :)

  4. Hi Mark,

    did you try this :
    in the “put_cat_icons() parameters” field of the widget ?

  5. If you can help me solve the problem, I can make a donation if you wish :)

  6. Hi! Thanks for your work on the plugin — it’s great! I tried your code to get the URL for category icons, but for some reason there are only 3 in the array, and there are 6 total categories with icons. I need them as background images, so I need the URL.

    Is there a way to get the URL for each icon by category ID? Such as something like:

    Thanks for any help you can give me!

  7. Never mind, I figured it out — just had to read through your documentation. Thanks!

  8. Hi

    This is a great plugin
    I am currently using this code to bring the icons onto the page:

    I have added the first section from this post into the functions file.
    what do i need to do with the second piece?

    Thanks for the help

  9. I wanted to use the category icons as og:image in my header. I’m using the lite version.

    I tried this:

    $caticons_url = extract_caticonsurl(get_cat_icon(‘echo=false’));

    but no joy. I changed it to this:

    $caticons_url = extract_caticonsurl(get_cat_icon_lite(‘echo=false’));


    runs outside the loop.

    See it here: