Using WordPress ‘atom_site_icon()’ PHP function

The atom_site_icon() WordPress PHP function is used to display the Site Icon in atom feeds.

Usage

To use the atom_site_icon() function, simply call it without any parameters as shown below:

atom_site_icon();

Given it is a display function, there is no direct output. Instead, it modifies the atom feed with the site’s icon.

Parameters

  • This function doesn’t take any parameters.

More information

See WordPress Developer Resources: atom_site_icon()

The atom_site_icon() function is used in the context of Atom feeds. It was introduced in WordPress version 4.3.0. The source code for this function can be found in wp-includes/general-template.php.

Related function: get_site_icon_url()

Examples

Displaying Site Icon in Atom Feeds

The following code shows how you can call the function in your feed template to display the site icon.

// In your feed-atom.php file
echo '<feed>';
atom_site_icon(); // Display site icon in the atom feed
echo '</feed>';

Checking if a Site Icon Exists Before Displaying

You might want to check if a site icon exists before trying to display it. Here’s how you can do that:

// Check if site icon exists
if (has_site_icon()) {
    atom_site_icon(); // Display site icon in the atom feed
}

Using with the bloginfo Function

You can use atom_site_icon() in conjunction with bloginfo('rss2_url') to specify the feed and display the site icon.

// Specify the feed url
$feed_url = bloginfo('rss2_url');

// Display the site icon in the atom feed
atom_site_icon();

Displaying Site Icon in a Custom Atom Feed

If you’re creating a custom Atom feed, you can use atom_site_icon() to add the site icon.

// Custom atom feed
echo '<feed xml:lang="en-US" xml:base="' . esc_url(home_url('/')) . '">';
atom_site_icon(); // Display site icon
echo '</feed>';

Using in a Template File

If you’re creating a template file for an Atom feed, you could call atom_site_icon() within the template to include the site icon.

// In your template file
echo '<feed>';
do_action('atom_head'); // Do necessary actions for Atom head
atom_site_icon(); // Display site icon
do_action('atom_entry'); // Do necessary actions for Atom entry
echo '</feed>';

Each example here calls the atom_site_icon() function to display the site’s icon in an Atom feed. The site icon is an important element for branding and recognition in feed readers.