We have known how to submit wordpress post url to microsoft bing search engine automatically when publishing. Here is the tutorial.
Submit URL to Bing Webmaster Tool Automatically When Publishing WordPress Post – WordPress Tutorial
How about wordpress category and tag? If we want to submit wordpress category and tag url to bing search engine when creating or editing them, we can do by these steps.
Step 1: Open bing webmaster tool to get your api key
You should get your api key in bing webmaster tool. Here is an example.
Step 2. Create a function to send category and tag url to bing search engine
We can create a send_cat_tag_to_bing() function to send wordpress category and tag url to bing search engine.
Here is an example code:
<?php function send_cat_tag_to_bing($tid){ $api_key = 'Your api key'; $api_url = 'http://ssl.bing.com/webmaster/api.svc/pox/SubmitUrl?apikey='.$api_key; $url = get_term_link($tid); $site_url = home_url(); $site_url = esc_url( $site_url ); $response = wp_remote_post($api_url, array( 'method' => 'POST', 'headers' => array('Content-Type'=>'application/json; charset=utf-8'), 'timeout' => 20, 'sslverify' => false, 'blocking' => true, 'body' => json_encode(array( 'siteUrl' => $site_url, 'url' => $url)) )); if ( is_wp_error( $response ) ) { $error_message = $response->get_error_message(); echo "Something went wrong: $error_message"; die(); } else { print_r($response); } } ?>
Open wordpress theme functions.php file and add this example code.
Step 3. Add two add_action in functions.php
We can run send_cat_tag_to_bing() function after having created or edited wordpress category and tag. In order to implement it, we can use code below.
add_action( 'created_term', 'do_cat_tag_created', 10, 2 ); function do_cat_tag_created( $term_id, $ttid){ send_cat_tag_to_bing($term_id); } add_action( 'edited_term', 'do_cat_tag_edited', 10, 2 ); function do_cat_tag_edited( $term_id, $taxonomy ){ send_cat_tag_to_bing($term_id); }
Save functions.php file, we can submit wordpress category and tag url to bing after having created or edited them.