ThemeShaper Forums » Thematic

[closed]

Conditionally Removing thematic_access

(13 posts)
  • Started 11 years ago by Val
  • Latest reply from helgatheviking
  • This topic is resolved
  1. I created home.php and uploaded to my child theme directory.

    I can conditionally add stylesheets to the head by checking if is_home() is true.
    I can conditionally add a "welcome" message in the header section.
    But I cannot conditionally remove thematic_access.
    It's all or nothing: I can remove it unconditionally, only.

    Any ideas as to why this code does not work?
    [code]
    // remove thematic_access()
    function remove_access() {
    if (is_home()) {
    remove_action('thematic_header','thematic_access',9);
    }
    }
    add_action('init', 'remove_access');
    [code]

    Thank you!

    Posted 11 years ago #
  2. Perhaps you can consider using is_front_page instead?

    From what I've understood, if a static page is used, it's best to use is_front_page because the is_home looks for the 'blog' (or default index) page.

    Chris also provided an interesting piece of code here using

    if (is_page_template('blog.php'))

    I haven't tested it myself, but perhaps it might be useful for you?

    -----------------------------------------------
    EDIT following Gene's post: corrected is_front_page

    Posted 11 years ago #
  3. Hi Val,

    I've run into this as well. It was hard for me hard to wrap my head around it at first. The problem is that by hooking into init the conditional tags will always return false. Basically, init fires too soon. Try hooking into template_redirect and your function will work the way you've intended it.

    Look to the codex for more info on action hooks: http://codex.wordpress.org/Plugin_API/Action_Reference

    @ Flick - Good call :) ...but the proper conditional tag for both "blog" and "front page" would be typed is_front_page that missing underscore will throw an error for calling an undefined function.

    Cheers,
    Gene

    Posted 11 years ago #
  4. @Gene: Thanks for the correction :) I should have checked the tag before posting. Luckily it seems I can still edit the post so I've changed it in case someone does a straight copy/paste in the future.

    /me needs to investigate action hooks more.

    Posted 11 years ago #
  5. @Gene,

    Thank you! Your suggestion launched an inquiry and solved my problem.

    I read through parts of the Codex: template hierarchy, API Plugins, actions vs filters and one WordPress forum post from mrfields explaining the difference between actions and filters (understand "objectively"; don't get it intuitively. Still unclear as to how to implement a filter. Shelved for later.)

    You're correct! init does fire way too soon for checking is_home()!

    If I understand what I've read, template_loader.php makes a call to the get_home_template function in theme.php. While that function is filterable, I'm not concerned with acting on that hook. (Would that be the correct way to say that?)

    I'm concerned with overriding the thematic_access function in header-extensions.php when home.php is loaded.

    Here is the path through the darkness:

    function remove_access() {
    // testing implicitly for home.php removes thematic_access from all files. Hmmm.
    // ? value of $template remains home.php for every subsequent query?
    // This does not work. Try something else.
    // if ($template = 'home.php') {
    //
    // Testing around is_home() appears to work, leaving thematic_access in place
    // on all other files. So far. Use this.
    //
       if is_home() {
    {
       remove_action('thematic_header','thematic_access',9);
       }
    } // close the function
    //
      // Take action
      // FYI substituting wp_head for template_redirect "works"
      // but seems to bog down the loading of the site
      // Here's what works now
    //
         add_action('template_redirect','remove_access');

    Onward!

    Val

    Posted 11 years ago #
  6. Hi Val & em hr,

    It works like a charm! Thanks for posting your solution!

    function page_checking() {
        if(is_front_page()){
            add_action('the_content', 'front_page_content');
        }
    }
    //as suggested by Gene add action to template_redirect
    add_action('template_redirect', 'page_checking');
    
    function front_page_content() {
        //you can work your magic here so it only shows the returned string on the front_page
        return 'x';
    }
    ?>
    
    Posted 11 years ago #
  7. Almost posted a new thread b/c I couldn't get this to work w/ if (is_page_template()). But checked out the link Gene posted to the WP action hooks and found that to conditionally remove #access based on a template then you have to edit Val's code to:

    add_action('wp_head','remove_access');

    do so love finding answers in the archives

    Posted 11 years ago #
  8. thank you in advance thematic geniuses

    Helga has already offered some help, much appreciated!

    i'm trying to remove the menu from one page. I've tried adding the following to my funcitions.php file with no luck

    function remove_access() {
    if (is_page('affiliate')) {
    remove_action('thematic_header','thematic_access',9);
    }
    add_action('template_redirect', 'remove_access');
    }

    AND THIS

    function remove_menu() {
    if (is_page('affiliate')) {
    remove_action('thematic_header','thematic_access',9);
    }
    add_action('template_redirect', 'remove_menu');
    }

    AND THIS

    created a template called 'affiliate'

    then added this to functions.php

    function remove_menu() {
    if (is_page_template('affiliate')) {
    remove_action('thematic_header','thematic_access',9);
    }
    add_action('wp_head','remove_access');
    }

    Don't know what i'm doint wrong. I can unconditionally remove the menu.

    Posted 11 years ago #
  9. For your template condition you have to use the name of your template file... so template.php and not just template. As for the page condition, I can only guess your page slug is not 'affiliate'

    function remove_access() {
      if (is_page('a-video-page')){
      remove_action('thematic_header','thematic_access',9);
      } else {
      // do nothing
      }
    }
    
    add_action('template_redirect', 'remove_access');
    function remove_access() {
       if (is_page_template('fullpage.php')){
        remove_action('thematic_header','thematic_access',9);
       } else {
       // do nothing
       }
    }
    
    add_action('wp_head', 'remove_access');

    Both of those work for me.

    Posted 11 years ago #
  10. caveat that the first snippet works for me on a page where the slug is a-video-post and the second snippet works on any page that is using my fullpage.php template

    assuming your affiliate template is affiliate.php you'd need:

    function remove_menu() {
    if (is_page_template('affiliate.php')) {
    remove_action('thematic_header','thematic_access',9);
    }
    add_action('wp_head','remove_access');
    }
    Posted 11 years ago #
  11. caveat that the first snippet works for me on a page where the slug is a-video-post and the second snippet works on any page that is using my fullpage.php template

    assuming your affiliate template is affiliate.php you'd need:

    function remove_menu() {
    if (is_page_template('affiliate.php')) {
    remove_action('thematic_header','thematic_access',9);
    }
    add_action('wp_head','remove_access');
    }
    Posted 11 years ago #
  12. I'll try these. Thank you

    Posted 11 years ago #
  13. wish I could edit my post for it's glaring typo (function name mismatch):

    function remove_access() {
    if (is_page_template('affiliate.php')) {
    remove_action('thematic_header','thematic_access',9);
    }
    add_action('wp_head','remove_access');
    }
    Posted 11 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.