//WordPress 百度普通收录 API 提交代码
add_action('save_post', 'fanlybaidu_dailysubmit', 10, 3);
function fanlybaidu_dailysubmit($post_id, $post, $update){
    if($post->post_status != 'publish' || get_post_meta($post_id,'Fanly_Submit',true)=='OK') return;
    $api = 'http://data.zz.baidu.com/urls?site='.$_SERVER['HTTP_HOST'].'&token=8g6UEKtV10MOPtBA';//普通收录复制过来
    $response = wp_remote_post($api, array(
        'headers' => array('Accept-Encoding'=>'','Content-Type'=>'text/plain'),
        'sslverify' => false,
        'blocking' => false,
        'body' => get_permalink($post_id)
    ));
    if ( !is_wp_error( $response ) ) {
        $res = json_decode($response['body'], true);
        if($res['success_daily']==1)update_post_meta($post_id, 'Fanly_Submit', 'OK');// OK 避免重复提交
    }
}
<!-- 百度自动推送代码-->
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>
<!-- 百度自动推送代码-->

发表评论

邮箱地址不会被公开。 必填项已用*标注