Astropix Apod

Astropix Apod is my first WordPress plugin and show the Astronomy Picture of the Day by Nasa. It work both in the posts and in the pages simply with a shortcode.

The project full code is reachable on my GitHub account

The plugin retrieve and parse the xml code from the Astronomy Picture of the Day RSS and then retrieve and parse the page with the picture of the day to get informations about the image like its url.

To retrieve the html pages the plugin use libcurl on PHP. The following is the function that implement the call.

function get_html_page($url, $timeout = 30)
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $results = curl_exec($ch);

    return $results;

To parse the html code the plugin use regular expressions like the following.

Sample regular expression

This regular expression get the url in the src property in a html img tag like the following

<img src="path/to/image.jpg" alt="Alternative text">

In the current version the plugin render a widget with the picture of the day (sometime a video), a label and the link to the original post by NASA.

Screenshot of the widget shown by Astropix Apod plugin in the version 1.0.0
Screenshot of the widget shown by Astropix Apod plugin in the version 1.0.0

The project is released under GNU General Public License v3.0.

For questions, comments or suggestions, use my contact page.


  Riccardo Giovarelli    All rights reserved 

Update – 12/2020

In the newer versions of Astropix Apod plugin the the use of libcurl have been deprecated to be compliant to the WordPress guidelines. Instead of libcurl were introduced two WordPress functions: wp_remote_get() and wp_remote_retrieve_body().


The function performs an HTTP request using the GET method and returns its response. It takes two parameters, the URL to retrieve and an array of request arguments (optional).


The function Retrieve only the body from the raw response. It takes one parameter, the HTTP response.