• Hello: I am using twenty eleven child theme on latest version of wordpress. I am pretty experienced in doing custom coding but all of my experience comes from using the “thesis” theme which works differently from most other themes. Anyway; I am trying to have a function only run in certain pages. I wrote the function and put it in my “functions.php” file and it worked but made change to the whole site. But when I added a “is_page” statement to try and restrict to one page only the code stopped working. Is this not doable in twentyeleven? Or is there some other way to conditionally run functions on some pages and not others?

    Please let me know,

    Gerard

Viewing 3 replies - 1 through 3 (of 3 total)
  • Themes don’t make any difference in the way the php is executed. People need to understand that the template is only a visual middle-man for your browser. Thesis and twenty Eleven in this regard are exactly the same.

    <?php if (is_page('your_page') || is_page('your_page')) { ?>
    // do something
    <?php } ?>
    Thread Starter charismaarts

    (@charismaarts)

    Thanks for answering. Here is my code:

    <?php
    
    function test_code() {
    
    if (is_page(10428)) {
    
    echo "***TESTING A FUNCTION****";
    }
    }
    
    add_action('after_setup_theme','test_code');
    
    ?>

    when I remove the “is_page” statement and also its closing “}” this function works fine; but putting this condition on it; it doesnt work at all; do you see anything wrong with my code?

    Thanks,

    Gerard

    <?php
    function test_code()
    {
       //whatever you want it to do
    }
    ?>
    <?php if (is_page('your_page') || is_page('your_page')) {
    // output function
    echo test_code();
    }else{
    //do this
    }
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘conditional functions?’ is closed to new replies.