目前我使用的是https版本的网站,一切都很好,我为https设置了网站主url,在查看帖子编辑器时有https permalink呈现。。在所有分类页面、主页等上一切正常。
但当我使用自定义站点地图功能(我为其创建了自己的插件)时,它会将站点地图与http:////
add_action("publish_post", "eg_create_sitemap");
add_action("publish_page", "eg_create_sitemap");
add_action( "save_post", "eg_create_sitemap" );
function eg_create_sitemap() {
if ( str_replace( \'-\', \'\', get_option( \'gmt_offset\' ) ) < 10 ) {
$tempo = \'-0\' . str_replace( \'-\', \'\', get_option( \'gmt_offset\' ) );
} else {
$tempo = get_option( \'gmt_offset\' );
}
if( strlen( $tempo ) == 3 ) { $tempo = $tempo . \':00\'; }
$postsForSitemap = get_posts( array(
\'numberposts\' => -1,
\'orderby\' => \'modified\',
\'post_type\' => array( \'post\', \'page\' ),
\'order\' => \'DESC\'
) );
$sitemap .= \'<?xml version="1.0" encoding="UTF-8"?>\' . \'<?xml-stylesheet type="text/xsl" href="\' .
esc_url( home_url( \'/\' ) ) . \'sitemap.xsl"?>\';
$sitemap .= "\\n" . \'<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\' . "\\n";
$sitemap .= "\\t" . \'<url>\' . "\\n" .
"\\t\\t" . \'<loc>\' . esc_url( home_url( \'/\' ) ) . \'</loc>\' .
"\\n\\t\\t" . \'<changefreq>daily</changefreq>\' .
"\\n\\t\\t" . \'<priority>1.0</priority>\' .
"\\n\\t" . \'</url>\' . "\\n";
foreach( $postsForSitemap as $post ) {
setup_postdata( $post);
$postdate = explode( " ", $post->post_modified );
$sitemap .= "\\t" . \'<url>\' . "\\n" .
"\\t\\t" . \'<loc>\' . get_permalink( $post->ID ) . \'</loc>\' .
"\\n\\t\\t" . \'<changefreq>Weekly</changefreq>\' .
"\\n\\t\\t" . \'<priority>1</priority>\' .
"\\n\\t" . \'</url>\' . "\\n";
}
$sitemap .= \'</urlset>\';
$fp = fopen( ABSPATH . "sitemap.xml", \'w\' );
fwrite( $fp, $sitemap );
fclose( $fp );
}
}