[英]i have to add prefix in some pages of my website and it show the conent of my existing page (mean without prefix page) in wordpress
$items = array( 'page' );
foreach( $items as $item )
{
add_filter( $item . '_link', 'my_link', 99, 2 );
}
function my_link($permalink, $post )
{
$pagearr = array('daily-dairy', 'free-downloads','latest-essay-topics','practice- tests','practice-exercises','video-lectures','contacts','sample1','sample3');
$arr = explode('/',$permalink);
if(in_array($arr[sizeof($arr)-2],$pagearr)){
$permalink = str_replace( get_site_url(), get_site_url() . '/institute', $permalink );
return $permalink;
}else{
return $permalink;
}
}
此代码在我的页面 URL 中添加了一个前缀,但在添加前缀时显示未找到页面。 我必须显示没有前缀页面的内容。
你在这里没有提到你为这些函数使用哪个钩子,你已经写在你的代码中。 看看下面的代码,告诉我你是否发现它对你有用。
function change_blog_links($post_link, $id=0){
$post = get_post($id);
if( is_object($post) && $post->post_type == 'post' || $post->post_type == 'page'){
return home_url('/YOUR_PREFIX/'. $post->post_name.'/');
}
return $post_link;
}
add_filter('post_link', 'change_blog_links', 1, 3);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.