在functions.php中添加以下代码即可,注意API的地址填写的是自己网站的的API地址
//百度收录API提交代码 add_action( 'save_post', 'bd_api', 10, 3 ); function bd_api( $post_id, $post, $update ) { if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) { return; } if($post->post_status != 'publish'){ return; } if($post->post_type!='post'){ return; } $urls = array( get_permalink($post_id) ); $api = '自己网站的百度推送API地址'; $ch = curl_init(); $options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode("\n", $urls), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), ); curl_setopt_array($ch, $options); curl_exec($ch); curl_close($ch); }
来了
@记录美好生活
欢迎欢迎~