adirondak Posted November 18, 2010 Share Posted November 18, 2010 I've been trying to implement the ID the Body Based on URL wordpress snippet. First issue seems to be a syntax error function curr_virtdir($echo=true){ $url = explode('/',$_SERVER['REQUEST_URI']); $dir = $url[1] ? $url[1] : 'home'; // defaults to this if in the root $dir = htmlentities(trim(strip_tags($dir))); // prevent injection into the DOM through this function if ($echo) echo $dir; return echo $dir; // ie. curr_virtdir(false) } function get_curr_virtdir(){ curr_virtdir(false); } I Get a syntax error on this line below return echo $dir; // ie. curr_virtdir(false) If i remove this line completly the script seems to work for in the following situation <body <?php id="<?php curr_virtdir(); ?>"> although I am trying to use the same functions as a conditional for my hardcoded navigation but it doesnt seem to work - any ideas? <li><a href="http://www.url.com/" class="<?php if ( get_curr_virtdir() == "home" ){echo "navhomecurrent";} else {echo "navhome";}?>">Home<span></span></a></li> <li><a href="http://www.url.com/solutions/solutions/" class="<?php if ( get_curr_virtdir() == "solutions" ){echo 'navsolutionscurrent';} else {echo 'navsolutions';}?>">Solutions<span></span></a></li> <li><a href="http://www.url.com/about-us/about-us/" class="<?php if ( get_curr_virtdir() == "about-us" ){echo "navaboutuscurrent";} else {echo "navaboutus";}?>">About us<span></span></a></li> Quote Link to comment https://forums.phpfreaks.com/topic/219074-body-id-based-on-url-wordpressphp/ Share on other sites More sharing options...
ManiacDan Posted November 18, 2010 Share Posted November 18, 2010 I Get a syntax error on this line belowThat's because that line is a syntax error. You can't return an echo. Just return the variable. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/219074-body-id-based-on-url-wordpressphp/#findComment-1136063 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.