WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] proper hook for "is_page"

[Resolved] proper hook for "is_page"

  • charismaarts
    Member

    @charismaarts

    Hello: I am trying to get some conditional code to work on my site using 2011 theme. I am trying to use the “is_page” and “is_single” statements to make the code conditional. I am doing functions in the “functions.php” file. when I try and have code be conditonal every part of the code works except for the “ia_page” part; for some reason it cannot recognize what page it is on. I think this may be caused by the hook I am running the function on. The hook I am using is ‘after_setup_theme’. Is there a better hook to use when trying to have code execute based on an “is_page” statement?

    Thanks,

    Gerard

Viewing 8 replies - 1 through 8 (of 8 total)
  • esmi
    Forum Moderator

    @esmi

    Do not edit the Twenty Eleven theme. It is the default WordPress theme and having access to an unedited version of the theme is vital when dealing with a range of site issues. First create a child theme for your changes.

    charismaarts
    Member

    @charismaarts

    I am sorry; i should have mentioned that I am doing that; sorry about that; so what I am referring to is a function in the child theme’s “functions.php” file…

    Thanks!

    @esmi did you accidentally mark this post as sticky?

    esmi
    Forum Moderator

    @esmi

    Not as far as I’m aware but I’ve un-stickied it anyway. Thanks for the heads-up.

    Have you set define('WP_DEBUG', true); in your wp-config.php file, so you see php errors?
    (Maybe try calling some arbitrary function like asdf() to see if you have error messages showing up)

    I’m not sure about when this hook is being called, but you could check if ‘is_page()’ is working by adding a simple wp_die(is_page()); (echo is_page(), would probably also work) instead of all your code, to find out if is_page is working at that moment. (Should just display true if it is a page and false if not)

    Let me know how things went.

    Marvin

    charismaarts
    Member

    @charismaarts

    thanks for that marvin; a little over my head but I will see if that will help…

    Do you make any progress? Do you have any questions? If this is fixed please mark it as resolved.

    charismaarts
    Member

    @charismaarts

    Hello Marvin: sorry I did not get back sooner but I have been working on a ton of stuff and honestly had to put this on the back burner. But I was finally able to work on this last night and made some good progress. It seems the problem was the php file i was putting the code in; i was able to get a (is_page) statement to work in the “page.php” file (in my child theme); and it did run on only the page specified…still not sure how hooks work and all that; but have made progress; thanks for all of your help and I will mark it resolved…

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Resolved] proper hook for "is_page"’ is closed to new replies.