ThemeShaper Forums » Thematic

[closed]

Operator Trouble In PHP function

(7 posts)
  • Started 8 years ago by soupking
  • Latest reply from soupking
  • This topic is resolved
  1. soupking
    Member

    Hi everybody,

    I've got one PHP function that works and one that doesn't.

    I found this function of a previous forum thread:

    http://forums.themeshaper.com/topic/how-to-remove-nav-above-help-me

    /* remove above navigation */
    function remove_nav_above(){
    	remove_action('thematic_navigation_above', 'thematic_nav_above', 2);
    }
    add_action('init','remove_nav_above');

    I tested it and it worked. However, when I apply a condition to it the function doesn't respond:

    /* remove above navigation for HOME ONLY*/
    function remove_nav_above(){
        if (is_home()) {
            remove_action('thematic_navigation_above', 'thematic_nav_above', 2);
        }
    }
    add_action('init','remove_nav_above');

    In another forum somebody suggested putting...

    wp_reset_query();

    in between two similar queries for some kind of cancellation purpose I believe it was. ?

    However, I put that before it as well, and nothing happened. Is there a basic syntax that I am forgetting to put in? I tried using "is_home" with another function the same way and it responded fine. The only difference was there was HTML tagging in the function.

    Not sure why it's not responding. ?

    Posted 8 years ago #
  2. i've run into this before. i think the problem is that the init hook is too early for WP to know whether you really are on the home page or not. so is_home() always returns false (and every other conditional test too)... and your function flops mightily.

    when i run into this, i usually pick a slightly later hook like template_redirect

    function remove_nav_above(){
    if (is_home()) {
    remove_action('thematic_navigation_above', 'thematic_nav_above', 2);
    }
    }
    add_action('template_redirect','remove_nav_above');

    Posted 8 years ago #
  3. soupking
    Member

    Awesome. Nailed it. That was the problem.

    It's not listed in these maps as far as I can tell:

    http://www.bluemandala.com/thematic/thematic-structure.html
    http://visualizing.thematic4you.com/

    So where is 'init' and 'template_redirect' in the scheme of all of this? Is that kind of a basis of child theme or not?

    I would have no idea to guess something like 'template redirect'. No way without forum response. Thanks again. :)

    Posted 8 years ago #
  4. hate to send you back to the codex, but there ya go:

    http://codex.wordpress.org/Plugin_API/Action_Reference

    init is not a thematic hook. it is a wordpress hook. but don't worry, i don't understand half of what is going on on this particular page.

    Posted 8 years ago #
  5. soupking
    Member

    Ahhh, cool. NP, happy to re-visit the Codex if I have half a clue where to put the basics.

    I feel like I just graduated from white belt having the ability to control section of my site. Dead in the water without that.

    Thanks!

    Posted 8 years ago #
  6. lol. welcome to the world of yellow belt, daniel-san. now that you can wax on and wax off, you must paint the fence.

    Posted 8 years ago #
  7. soupking
    Member

    Heh, I could use the exercise, believe me. (no, the avatar is no indication :)

    Posted 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.