WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] proper hook for "is_page" (9 posts)

  1. charismaarts
    Member
    Posted 2 years ago #

    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

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    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.

  3. charismaarts
    Member
    Posted 2 years ago #

    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!

  4. marv51
    Member
    Posted 2 years ago #

    @esmi did you accidentally mark this post as sticky?

  5. esmi
    Forum Moderator
    Posted 2 years ago #

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

  6. marv51
    Member
    Posted 2 years ago #

    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

  7. charismaarts
    Member
    Posted 2 years ago #

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

  8. marv51
    Member
    Posted 2 years ago #

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

  9. charismaarts
    Member
    Posted 2 years ago #

    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...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.