Problem with RSS!

Evgenio999

Newbie
Joined
Aug 15, 2023
Messages
43
Reaction score
9
Hi all! Help me figure it out, I’ve already spent 2 days(((problem in setting up the site’s RSS feed on WordPress.

How can I make the article appear along with HTML tags in the RSS feed? My article turns out to be solid text without tags and I don’t know how to fix it.

Now the article text is inside <content:encoded><![CDATA[?...]]>............</content:encoded>

Maybe I need to remove these tags or how to fix this error in WordPress? Thanks everyone for your answer!
 
You can try with the following code, add it to functions.php:
PHP:
add_filter ('the_content', 'my_custom_feed');
function my_custom_feed ($content) {
    global $post;
    if (! is_feed ()) return $content;
    // Remove all shortcodes
    $content = strip_shortcodes ($post->post_content);
    $content = strip_tags ($content);
    // Remove all html tags, except these
    $my_allowed_tags = array (
        'p' => array (),
        'strong' => array (),
        'em' => array (),
        'img' => array ('src' => array (), 'width' => array (), 'height' => array ()),
    );
    $content = wp_kses ($content, $my_allowed_tags);
    // Balance tags
    $content = balanceTags ($content, true);
    return $content;
}

Or you can make a new plugin to make things even better:
PHP:
<?php
/*
Plugin Name: My Custom Feed
Description: This plugin removes HTML tags from the RSS feed.
Version: 1.0
Author: HiDeath
*/

add_filter ('the_content', 'my_custom_feed');
function my_custom_feed ($content) {
    global $post;
    if (! is_feed ()) return $content;
    // Remove all shortcodes
    $content = strip_shortcodes ($post->post_content);
    $content = strip_tags ($content);
    // Remove all html tags, except these
    $my_allowed_tags = array (
        'p' => array (),
        'strong' => array (),
        'em' => array (),
        'img' => array ('src' => array (), 'width' => array (), 'height' => array ()),
    );
    $content = wp_kses ($content, $my_allowed_tags);
    // Balance tags
    $content = balanceTags ($content, true);
    return $content;
}
?>
Save this code in a file with a .php extension and upload it to your WordPress plugins directory.
After that, you should be able to activate it from the WordPress admin panel.

Hope this helps,
Don't thank me, thank gpt-4 :)
 
Back
Top