Why P or DIV in RSS/feed code for featured image?



The content of a post contains HTML, which is output in the feed within CDATA wrappers. The feed itself is XML.

You might have to search again, for up-to-date information.
Adding images to RSS feeds was started in the early 2000s. The <enclosure> mechanism was used.

RSS enclosures are a way of attaching multimedia content to RSS feeds by providing the URL of a file associated with an entry, such as an MP3 file to a music recommendation or a photo to a diary entry. Unlike e-mail attachments, enclosures are merely hyperlinks to files. The actual file data is not embedded into the feed (unless a data URL is used). Support and implementation among aggregators varies

If you are simply adding a link to the HTML content, it shouldn’t matter whether it is in a <p> tag or a <div> tag, or no tag at all.
In WordPress, excerpts can be manually written, and contain HTML. Excerpts that are generated from content have the HTML tags stripped out, so the link would have to be added after the stripping happens.

By 2009, it was expanded to Media RSS Spec, which handles more types of files.

Media RSS is a new RSS module that supplements the <enclosure> capabilities of RSS 2.0. RSS enclosures are already being used to syndicate audio files and images. Media RSS extends enclosures to handle other media types, such as short films or TV, as well as provide additional metadata with the media.

I suggest you use a plugin for adding the images.

Thank you for an interesting answer!
Hmm… I have googled a lot and everybody so far says it so easy, just add this code (with small variations). I know how to use PHP snippet plugin, so I was hoping to not have to add an extra plugin.

Just wanted to be sure I was using an up to date code, modified for Gutenberg and a responsive world 2021.

But as you say, this goes many years back and I find it hard to know if it is still relevant today, or if things have changed but people are lazy or non tech (like me) and still repeat the same old code…



Right, the snippets you mentioned weren’t using <enclosure>. They just put the link in with the other HTML.
I suggested a plugin because the author would have researched it, tested it, and maintains it, so you don’t have to know all that stuff. Or you can find a plugin and just read the code so you know the answer to your question.

When you add code to WordPress, you have to add it somewhere. A plugin is the best place to add code. When you use a snippet plugin, you are storing code in the database, which is not as good an idea as storing it in code files in the plugin folder. There are protections in place for the code files, but rogue plugins or hacks can compromise your database.

Thank you, good information about snippets and database! And I think you have convinced me to find a light plugin instead…

Source link