• I have a static front home page. My blog is located at mysite.com/blog/.

    Is there a conditional that says the following:

    If on /blog/
    Then show this
    Else
    Something else
    End if

    I basically have a different navigation I want to show when only on the blog.

Viewing 3 replies - 1 through 3 (of 3 total)
  • This will check for /blog/ anywhere in URL, but chances are you will only have /blog/ in URL when at the blog.

    / defines start and end of the pattern to match so the / in blog are escaped \/

    <?php
    if(preg_match("/\/blog\//",$_SERVER['REQUEST_URI'])){
       //if /blog/ is anywhere in the URL..
    }else{
       //if /blog/ is not in URL
    }
    ?>

    Far better to use WP conditionals:

    <?php if( is_home() ) :?>
    [ show this]
    <?php else:?>
    [ something else]
    <?php endif;>
    Thread Starter mattmikulla

    (@mattmikulla)

    Esmi, I don’t think that will work since my home page is not my blog but static content for the front of the site.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘If conditional for a directory or when on /blog’ is closed to new replies.