adding wordpress yoast SEO canonical url from "transition_post_status" hook

I am using transition_post_status hook to add get some data at the time of post is publish but i can access any variable

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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信