I am using transition_post_status
hook to add get some data at the time of post is publish but i can access any variables but when i am trying to set canonical url from add_filter
it is return 500 error
// Add the hook action
add_action('transition_post_status', 'send_new_post', 10, 3);
// Listen for publishing of a new post
function send_new_post($new_status, $old_status, $post) {
if('publish' === $new_status && $post->post_type === 'post') {
print_r('this is done');
$post_meta = get_post_meta($post->ID, '', true);
$object_id = $post_meta['mydo_post_id'][0];
$canonical_url = '/'.$object_id;
add_filter( 'wpseo_canonical', 'add_canonical' );
function add_canonical($url){
return $canonical_url;
}
}
}
Above is my code i am using can anyone help?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745625822a4636798.html
评论列表(0条)