Dental SEO Auto Sitemap Plugin
Download and install this plugin to auto-ping Google and Bing when posts are published.
Installation Instructions:
- Download the plugin file below
- Go to WordPress Admin → Plugins → Add New → Upload Plugin
- Upload dental-seo-sitemap-plugin.php
- Activate the plugin
The plugin will automatically ping search engines when you publish, update, or delete posts.
Plugin Code:
<?php
/**
* Plugin Name: Dental SEO Auto Sitemap
* Description: Auto-generates and submits sitemaps
* Version: 1.0
*/
// Prevent direct access
if (!defined('ABSPATH')) exit;
class DentalSEO_Sitemap {
private $sites = array(
'doktorgigi.com.my',
'dentistnearme.com.my',
'bracesmurah.com.my'
);
public function __construct() {
add_action('publish_post', array($this, 'on_post_publish'));
add_action('wp_update_post', array($this, 'on_post_update'));
add_action('wp_trash_post', array($this, 'on_post_delete'));
// Daily sitemap regeneration
if (!wp_next_scheduled('dental_seo_daily_sitemap')) {
wp_schedule_event(time(), 'daily', 'dental_seo_daily_sitemap');
}
add_action('dental_seo_daily_sitemap', array($this, 'regenerate_all_sitemaps'));
}
public function on_post_publish($post_id) {
$this->ping_search_engines();
$this->log_event('publish', $post_id);
}
public function on_post_update($post_id) {
$this->ping_search_engines();
$this->log_event('update', $post_id);
}
public function on_post_delete($post_id) {
$this->ping_search_engines();
$this->log_event('delete', $post_id);
}
private function ping_search_engines() {
$sitemaps = array(
'https://doktorgigi.com.my/sitemap-doktorgigi.xml',
'https://dentistnearme.com.my/sitemap-dentistnearme.xml',
'https://bracesmurah.com.my/sitemap-bracesmurah.xml'
);
foreach ($sitemaps as $sitemap) {
// Google
wp_remote_get('https://www.google.com/ping?sitemap=' . urlencode($sitemap));
// Bing
wp_remote_get('https://www.bing.com/ping?sitemap=' . urlencode($sitemap));
}
}
private function log_event($type, $post_id) {
$log = array(
'time' => current_time('mysql'),
'type' => $type,
'post_id' => $post_id,
'url' => get_permalink($post_id)
);
error_log('Dental SEO: ' . json_encode($log));
}
public function regenerate_all_sitemaps() {
// Trigger sitemap regeneration
do_action('dental_seo_regenerate_sitemaps');
}
}
// Initialize
new DentalSEO_Sitemap();