Jump to content

Body ID Based on URL - Wordpress/PHP


adirondak

Recommended Posts

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>

 

Link to comment
https://forums.phpfreaks.com/topic/219074-body-id-based-on-url-wordpressphp/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.