最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

adding wordpress yoast SEO canonical url from "transition_post_status" hook

programmeradmin2浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论