I wanted to add the PHP code below to the `functions.php` file that makes some changes to the image URLs in RSS feeds, but there’s no `functions.php` in the Twenty Twenty-Three theme.
function adjust_feed_image_url($content) {
// Load the content into a DOMDocument
$doc = new DOMDocument();
@$doc->loadHTML(‘<?xml version=”1.0″ encoding=”UTF-8″?>’ . $content); // The ‘@’ is used to suppress XML parsing warnings
// Look for the <image> tag
$images = $doc->getElementsByTagName(‘image’);
foreach ($images as $image) {
// Get the <url> tag
$urls = $image->getElementsByTagName(‘url’);
foreach ($urls as $url) {
// Parse the URL to remove query parameters
$parsed_url = parse_url($url->nodeValue);
$clean_url = ‘https://talebotai.com’ . $parsed_url[‘path’]; // Updated hostname
// Update the <url> node value
$url->nodeValue = $clean_url;
}
}
// Save the modified content and return
return $doc->saveXML();
}
add_filter(‘the_content_feed’, ‘adjust_feed_image_url’);
How can I achieve this with the Twenty Twenty-Three theme?
[ad_2]