我想与Facebook
网站中的每个新帖子分享wordpress
。这个任务需要哪个钩子?
我写了这段代码,但它不起作用=(
function on_all_status_transitions $new_status, $old_status, $post) {
if ($new_status == 'publish') {
$url = 'http://facebook.com/sharer.php?u=' . get_permalink($post->ID);
wp_redirect($url);
// header('Location: '. $url); -> it doesn't work too =(
}
}
add_action('transition_post_status', 'on_all_status_transitions', 10, 3);
答案 0 :(得分:0)
使用publish_post
挂钩,只要发布帖子就会触发
function on_all_status_transitions( $ID, $post) {
$url = 'http://facebook.com/sharer.php?u=' . get_permalink($ID);
wp_redirect($url);
exit;
}
add_action( 'publish_post', 'on_all_status_transitions', 10, 3 );