简体   繁体   中英

wordpress if not index echo something else

I'd like to give my title <?php echo get_the_title(); ?> <?php echo get_the_title(); ?> conditional statement. If not HOMEPAGE just display whatever it is = <?php echo get_the_title(); ?> <?php echo get_the_title(); ?> . if HOMEPAGE display THIS IS + <?php echo get_the_title(); ?> THIS IS + <?php echo get_the_title(); ?>

so the syntax should be

<?php

$path = $_SERVER['REQUEST_URI'];
$page = basename($path);
$page = basename($path, '.php');

?>


<?php if($page == 'index') 
  {echo 'This is'. get_the_title();  }
   else 
   {echo get_the_title();}
?>

the problem is I dont really know in wordpress do we use the same way or something smarter or easier.

OH, FORGOT! Actually, my index/homepage is not real index, it is the page called "HOMEPAGE " setting from Reading Settings -> a static page, front page => HOMEPAGE

Thanks for any advice.

place your code in functions.php

function title_edit($title){
    if(!is_front_page() || get_post_type() != 'page') return $title;
    $title = 'Home: '.$title;
    return $title;
}

add_filter('the_title','title_edit');

Problem solved thanks @silentboy

<?php if(is_front_page()) 
    echo 'This is'.get_the_title(); 
     else echo get_the_title(); ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM