我试图获得与链接到外部链接的链接标题相同的插件Pages Link To。我不想使用插件的原因是链接在保存帖子时动态生成,但我无法使用外部链接更新帖子的永久链接。将链接标题链接到外部链接而不是链接
下面是我的functions.php代码:
function savepost($post_id) {
if($_POST['post_type'] == 'books'){
$genre = strip_tags(get_field('genre'));
$author = strip_tags(get_field('author'));
$extlink = "http://www.".$genre."/".$author.".com";
update_post_meta($post_id, 'extlink', $extlink);
$url = strip_tags(get_field('extlink',$post));
update_post_meta($post_id, 'post_link', $url);
}
}
add_action('save_post', 'savepost');
我尝试中,我分配了一个模板后的另一种方法,这样,当后加载它重定向到链接,但它不会重定向
我的代码
<?php
ob_start();
?>
<?php
/**
* Template Name: post Redirection Template
*/
get_header();
$redirecturl = strip_tags(get_field('extlink',$post));
wp_redirect($redirect_url);
get_sidebar();
get_footer();
?>
<?php
ob_end_flush();
?>
我更新了代码并尝试了你所说的,但它并没有取代默认的永久链接..plz正确的代码我似乎无法弄清楚什么是错的 – user3449454
你在哪里更新你的代码?在上面的functions.php中? – michaelrmcneill
是把它放在functions.php – user3449454