• Hi,

    I’m using the [ics_calendar] shortcode on my WordPress site, and I’d like to know if there is a way to display a custom error message when the ICS file URL passed in the shortcode cannot be reached (for example, if the URL returns a 404 error or is missing).

    Instead of the default behavior, I would like to display a simple message like “No dates available” if the URL is invalid or inaccessible.

    Is there a way to implement this using the plugin’s current features, or would it require a custom solution? Any guidance or suggestions would be greatly appreciated.

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author room34

    (@room34)

    At present there is not a way to do this. However I don’t think it would be a good idea to add it as an option. If the source feed URL is invalid, it will never display any events, so the site admin who is setting it up should realize there’s a problem and fix the URL. There is currently a PHP error message that displays when the feed URL is invalid, and consistent with standard PHP rules it only displays if the display_errors PHP option is enabled.

    Thread Starter vincentthinkr

    (@vincentthinkr)

    thanks for your answer,

    what do you thinks about this solution :

    function custom_ics_calendar_shortcode($atts) {

    $a = shortcode_atts( array(
    'url' => '',
    'title' => 'true',
    'view' => 'month',
    'maskinfo' => '',
    'showendtimes' => 'false',
    'format' => 'j F'
    ), $atts );


    $response = wp_remote_head( $a['url'] );

    if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {

    return '<p>No dates available</p>';
    } else {

    $shortcode = '[ics_calendar url="' . esc_url($a['url']) . '"'
    . ' title="' . esc_attr($a['title']) . '"'
    . ' view="' . esc_attr($a['view']) . '"'
    . ' maskinfo="' . esc_attr($a['maskinfo']) . '"'
    . ' showendtimes="' . esc_attr($a['showendtimes']) . '"'
    . ' format="' . esc_attr($a['format']) . '"]';

    return do_shortcode($shortcode);
    }
    }

    add_shortcode('custom_ics_calendar', 'custom_ics_calendar_shortcode');

    That seems relevant to me, but am I perhaps missing something?

    Plugin Author room34

    (@room34)

    That seems like it would work, but it may not be very efficient because it will force the feed URL to be retrieved multiple times (or at least once per page load even when ICS Calendar has the feed cached).

    I’m curious as to why you want to have this message display, since it’s only going to occur when there’s an error with your source feed. It would be best to fix the feed.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display Custom Error Message When ICS URL Is Unavailable (404 Error)’ is closed to new replies.