• Not sure if this is possible.

    I am importing an RSS feed to display as a widget in the sidebar of my page, which has the title as the date in the format (eg Friday, 10 Jul 2020) I would like to be able to reformat it to be (Friday July 10th), Is this possible and if so any help would be gratefully appreiated.

    Thanks

    • This topic was modified 4 years, 4 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    In theory it’s possible. How easy it is depends upon how the widget is coded. PHP can convert any date string into a timestamp with strtotime(). You can then use date() to format the timestamp into any format you wish.

    Ideally the widget would have a filter we could hook to alter content in this manner. Otherwise you’d probably need to create your own widget using the current one’s source code as a starting point.

    Thread Starter twistsd

    (@twistsd)

    Thanks for your reply. I am quite new to editing photos files. I am using the standard WordPress RSS widget in the sidebar, what edits would I need to make? Thanks

    Moderator bcworkz

    (@bcworkz)

    The filter ‘date_i18n’ can be used to reformat the date being returned by the function of the same name (used to format the date from feed data). The date’s timestamp is passed as the third parameter so use of strtotime() is not necessary. This filter will affect much more date display than that of the widget, so a filter hook should only be added in the correct context. The ‘widget_title’ filter fires before ‘date_i18n’, so can be used to only add in the right context. Only add a callback to ‘date_i18n’ when the passed widget title matches the title of your RSS widget instance.

    I don’t see an easy way to remove the callback again after its use in no longer needed. If there is no subsequent date output after the widget this may not be an issue. If another widget occurs after RSS, maybe ‘widget_title’ can be used again to remove as well.

    Unless you already have a child theme or plugin to contain custom code, you should create one or the other (plugins are easier to create). It’s best to avoid editing code files, especially WP core files. Add code to hook the previously mentioned filters with callbacks to effect change as I’ve described.

    Thread Starter twistsd

    (@twistsd)

    Thanks,

    I am using a child theme, I will try and identify the correct pho file that needs amending.

    Moderator bcworkz

    (@bcworkz)

    FWIW the widget source code is listed in the developer docs. But the applicable date formatting happens in the fetch_feed() call. Do not edit that code though. It’s very tempting as the change would be very minor. Sadly, doing it right is more complicated. Hook the related filters as I’ve described earlier. All related custom code can reside in your child’s functions.php.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Editing imported RSS feed title’ is closed to new replies.