Hello,
I use the following code to add the date to an RSS-created article.
function my_add_date_to_title($title, $id) {
// Check if we're in the loop or not
// This should exclude menu items
if ( !is_admin() && in_the_loop() && has_category('polizeibericht', $id)) {
// First get the default date format
// Alternatively, you can specify your
// own date format instead
$date_format = get_option('date_format');
// Now get the date
$date = get_the_date($date_format, $id); // Should return a string
// Now put our string together and return it
// You can of course tweak the markup here if you want
$title .= ' ' . $date ;
}
// Now return the string
return $title;
}
// Hook our function to the 'the_title' filter
// Note the last arg: we specify '2' because we want the filter
// to pass us both the title AND the ID to our function
add_filter('the_title','my_add_date_to_title',10,2);
Unfortunately, the date is not displayed in the URL of the article, so I only have the same two words as URL.
As an example https://salzsau-panorama.de/blaulicht/polizeibericht/
How can I add the date to the URL?
Thanks
Hi,
Maybe I am misunderstanding this, but the date can be displayed in the URL by changing the permalink structure
– https://www.screencast.com/t/8lIdsfwm
Or even create custom permalinks
– https://codex.wordpress.org/Using_Permalinks
Thanks
Hi Simon,
It is correct that the date can be displayed in the URL by changing the permalink.
Only if I import the feed and choose title as ‘policy report’, then yes to the URL every day increasing number attached
Example: In the third import policy report-3, at the fourteenth import policy report-14 and so on.
That does not look really nice, I think
And with the code function I would like to reach, which is attached to the title a date, as for example ‘Policereport- from-14-02-2018 (German date notation)