从“ transition_post_status”钩子添加wordpress yoast SEO规范网址

时间:2019-04-05 07:15:56

标签: wordpress hook canonical-link

我正在使用transition_post_status挂钩在发布时添加获取一些数据,但是我可以访问任何变量,但是当我尝试从add_filter设置规范网址时会返回500错误

// 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 = 'https://mylofamily.com/article/'.$object_id;
    add_filter( 'wpseo_canonical', 'add_canonical' );
    function add_canonical($url){
        return $canonical_url;
    }
  }
}

以上是我正在使用的代码,任何人都可以帮忙吗?

0 个答案:

没有答案