I want to write plugin which has the ability to change the start page according to a get parameter:
The following code is the full plugin.
function GET_Different_Page_on_front_parameter() {
if (!session_id()) {
session_start();
}
if(!($_SESSION['start'])){
$_SESSION['start']=$_GET['view'];
}
else{}
}
add_action( 'init', 'GET_Different_Page_on_front_parameter');
add_action( 'pre_get_posts', 'redirect_another_homepage');
function redirect_another_homepage(){
$front_page_slug=$_SESSION['start'];
$front_page_id=get_page_by_path($front_page_slug);
$content = $content.$front_page_id->ID;
if(is_home()){
$page=get_permalink($front_page_id->ID);
?>
<script type="text/javascript">
<!--
window.location.href = "<?php echo $page;?>";
//–>
</script>
<?php
}else{}}
I thought it was working yesterday but maybe it just look like it was working.
I also could put you as contributor in WordPress plugin repository.
is_home()
is not the home page. It returns true on the blog posts index. For the site front page specifically, useis_front_page()
.