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

How do I change the permalink of a scheduled post so that it can be linked to?

programmeradmin1浏览0评论

When you create a post of any type (either post or page or custom taxonomy) it gets a permalink that visitors can click on and visit.

 /

However, if you Publish the post, BUT make the publish date in the future, the post is shown as 'Scheduled' in the Admin and the permalink shows like so:

 /?p=2848

And then also, when I try to share the post on Facebook, it does not share properly (ie. the preview text and image do not appear).

I include the FB include code just for completeness. But what I really want to know is--how do I get a 'scheduled' post behave like a 'published' post when it comes to the purposes of the permalink.

 function add_opengraph_doctype( $output ) {
    return $output . ' xmlns:og="/" xmlns:fb=""';
}
 add_filter('language_attributes', 'add_opengraph_doctype');

 function insert_fb_in_head() {

 $og_title = get_post_meta( get_the_ID(), '_yoast_wpseo_title', true);

 $og_description = get_post_meta( get_the_ID(), '_yoast_wpseo_metadesc', true);

 if( ! $og_title)   
    $og_title = get_the_title();

 if( ! $og_description){    
    $og_description = get_the_excerpt();
    if ( strlen($og_description) > 156)
        $og_description = substr( get_the_excerpt(), 0, 153) . '...';
}

echo ('<meta property="og:title" content="' . $og_title . '"/>' . PHP_EOL);
echo ('<meta property="og:type" content="article"/>' . PHP_EOL);
echo ('<meta property="og:url" content="' . get_permalink() . '"/>' . PHP_EOL);
echo ('<meta property="og:site_name" content="Sea-Tac Noise Information"/>' . PHP_EOL);
echo ('<meta property="og:description" content="' . strip_tags( $og_description) . '"/>' . PHP_EOL);

  //dpm(    has_post_thumbnail( $post->ID ));
    //$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
    //dpm($thumbnail_src);

if( has_post_thumbnail( $post->ID )) { //the post has a featured image, use a default image
    $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
    //dpm($thumbnail_src);
    echo ('<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>' . PHP_EOL);
    echo ('<meta property="og:image:width" content="' . esc_attr( $thumbnail_src[1] ) . '"/>' . PHP_EOL);
    echo ('<meta property="og:image:height" content="' . esc_attr( $thumbnail_src[2] ) . '"/>' . PHP_EOL);      
}

$default_image=".png";             echo ('<meta property="og:image" content="' . $default_image . '"/>' . PHP_EOL);
    echo ('<meta property="og:image:width" content="250"/>' . PHP_EOL);
    echo ('<meta property="og:image:height" content="250"/>' . PHP_EOL);        
  }
  add_action( 'wp_head', 'insert_fb_in_head', 5 );
发布评论

评论列表(0)

  1. 暂无评论