Yes, wordpress images auto added in post or page sitemap but osclass no option. So better image indexing its required. in GSC there are lot of error under Page indexing Crawled - currently not indexed - like
huge img urls - https: //xyz. com/oc-content/uploads/1/257.webp & YES this urls are no need to index in Google search but for max images indexing and shown in Google Image Search if we add this then its add value. after adding this image sitemap still GSC error not gone, but atleast max image index.
So, I played around code and make 1 php code file to generate this sitemap. Have a look and suggest any improvement if anything wrong in this.
After add this file to your Root directory - just hit this URL and your sitemap generated.
I hope our community will help a lot who want more advanced SEO approach.
attached .txt file open and save as .php and upload to your root directory of osclass.
or see full code here -
<?php
// Prevent output buffering issues
if (ob_get_length()) ob_end_clean();
function decode_xml_entities($string) {
return html_entity_decode($string, ENT_QUOTES | ENT_XML1, 'UTF-8');
}
// Load Osclass Core
require_once dirname(__FILE__) . '/oc-load.php';
require_once osc_base_path() . 'oc-includes/osclass/model/Item.php';
require_once osc_base_path() . 'oc-includes/osclass/model/ItemResource.php';
// Define the sitemap file path
$filename = osc_base_path() . 'sitemap-images.xml';
$sitemap_url = osc_base_url() . 'sitemap-images.xml';
@unlink($filename);
// Start capturing XML output
ob_start();
// XML Declaration - Ensure it's the first output
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<?xml-stylesheet type="text/xsl" href="' . osc_base_url() . 'oc-content/plugins/sitemap_pro/css/stylesheet.xsl"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" ';
echo 'xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">' . "\n";
// Initialize counters
$total_items = 0;
$total_images = 0;
// Get all active items
$itemModel = new Item();
$items = $itemModel->listWhere("b_active = 1 AND b_enabled = 1", "pk_i_id DESC", 0, 5000);
foreach ($items as $item) {
$item_id = $item['pk_i_id'];
$item_url = osc_item_url_from_item($item);
if (!empty($item_url)) {
$total_items++;
echo " <url>\n";
echo " <loc>" . htmlspecialchars($item_url, ENT_XML1, 'UTF-8') . "</loc>\n";
// Get correct images
$resourceModel = new ItemResource();
$resources = $resourceModel->getResources($item_id);
$item_image_count = 0;
foreach ($resources as $resource) {
$image_filename = $resource['pk_i_id'] . ".webp";
$image_dir = "0"; // Osclass default directory
$image_path = osc_base_url() . "oc-content/uploads/{$image_dir}/{$image_filename}";
if (!filter_var($image_path, FILTER_VALIDATE_URL)) {
continue;
}
//$image_title = htmlspecialchars(html_entity_decode($item['s_title'], ENT_QUOTES | ENT_XML1, 'UTF-8'), ENT_XML1, 'UTF-8');
$image_title = !empty($item['s_title']) ? html_entity_decode(htmlspecialchars($item['s_title'], ENT_XML1, 'UTF-8'), ENT_QUOTES | ENT_XML1, 'UTF-8') : "Spa Image";
echo " <image:image>\n";
echo " <image:loc>" . htmlspecialchars($image_path, ENT_XML1, 'UTF-8') . "</image:loc>\n";
echo " <image:title>" . $image_title . "</image:title>\n";
echo " </image:image>\n";
$item_image_count++;
}
$total_images += $item_image_count;
echo " </url>\n";
}
}
echo "</urlset>\n";
// Save the XML output to the sitemap file
$xml_output = ob_get_clean();
file_put_contents($filename, $xml_output);
// Redirect to success page with message (NO XML OUTPUT HERE)
header("Content-Type: text/html; charset=UTF-8");
echo "<h2 style='color: green;'>✅ Image Sitemap Successfully Generated!</h2>";
echo "<p><strong>📌 View Sitemap:</strong> <a href='{$sitemap_url}' target='_blank'>{$sitemap_url}</a></p>";
echo "<p><strong>🔢 Total Items:</strong> {$total_items} | <strong>Total Images:</strong> {$total_images}</p>";
exit;
?>