0

I'm working on modifying the Keyboard Shortcut Navigation plugin to fit my site. Here's the plugin: http://wordpress.org/extend/plugins/easy-keyboard-shortcut-navigation/

I don't want this plugin to run on page 2020. I've tried && !is_page('2020') and || !is_page('2020') in the elseif below, but it keeps running the function.

Any ideas?

Edit update: As requested, I'm removing the snippet and including the full code from the plugin located at the above URL.

add_action('wp_footer','keyboard_shortcut_navigation');
function keyboard_shortcut_navigation(){
    global $paged, $wp_query;
    if ( !$max_page )
        $max_page = $wp_query->max_num_pages;
    if ( !$paged )
        $paged = 1;
    $nextpage = intval($paged) + 1;
?>
<?php if( is_single() ) : ?>
<script type="text/javascript">
    document.onkeydown = chang_page;function chang_page(e) {
    var e = e || event,
    keycode = e.which || e.keyCode;
    var obj = e.target || e.srcElement;
    if(obj.tagName.toLowerCase()=="textarea"){return;}
    if(obj.tagName.toLowerCase()=="input"){return;}
    if (keycode == 33 || keycode == 37) location = '<?php echo get_permalink(get_adjacent_post(false,'',false)); ?>';
    if (keycode == 34 || keycode == 39) location = '<?php echo get_permalink(get_adjacent_post(false,'',true)); ?>';
    }
</script>
<?php elseif( is_home() || is_category() ) : ?>
<script type="text/javascript">
    document.onkeydown = chang_page;function chang_page(e) {
        var e = e || event,
        keycode = e.which || e.keyCode;
        var obj = e.target || e.srcElement;
        if(obj.tagName.toLowerCase()=="textarea"){return;}
        if(obj.tagName.toLowerCase()=="input"){return;}
        if (keycode == 33 || keycode == 37) location = '<?php echo get_previous_posts_page_link(); ?>';
        if (keycode == 34 || keycode == 39) 
        <?php if ( $nextpage <= $max_page ) : ?>
            location = '<?php echo get_next_posts_page_link(); ?>';
        <?php else : ?>
            location = '<?php echo get_pagenum_link( $max_page ); ?>';  
        <?php endif; ?>
    }
</script>
<?php endif; ?>
<?php
}
3
  • Please post more code. How/where that snippet gets hooked is important.
    – s_ha_dum
    Commented Dec 16, 2012 at 21:02
  • Will do, wasn't sure if it was OK to post another authors plugin code? I'll edit my question with the code as requested.
    – Pat
    Commented Dec 16, 2012 at 21:05
  • Is this site publicly accessible? Do you have an URL?
    – s_ha_dum
    Commented Dec 16, 2012 at 22:05

1 Answer 1

1

This works for a page on my site with ID 675:

function tst($content) {
  if (is_page(675)) print('howdy');
}
add_action('wp_footer','tst');

I would just interrupt the function right at the top.

function keyboard_shortcut_navigation(){
    global $paged, $wp_query;
    if (is_page(2020)) return; // for a post with ID 2020
    if (is_page('2020')) return; // for a post with slug or title "2020"
    // you should only need one of those
    // ... the rest

If you are talking a posts instead of pages then maybe what you want is this:

// old
<?php if( is_single() ) : ?>
// new
<?php if( is_single() && !is_single(2020)) : ?>
// use quotes if 2020 is the title or the slug

You are hacking somebody else's plugin so you are likely to have problems when you update. I'd contact the author and ask for a hook in the next release that will allow you to do this without hacking anything.

8
  • I put in both of those is_page examples to test it out, and the javascript is still loading on my page 2020. It's very strange, your tst function didn't work either. Since I'm looking for a little customization, and to prevent update problems, I've copied this to my functions.php, would that make a difference?
    – Pat
    Commented Dec 16, 2012 at 21:38
  • I ran that function from functions.php. Is the original plugin still active?
    – s_ha_dum
    Commented Dec 16, 2012 at 21:45
  • Nope, not active. What's weird is I've done this before, but for some reason it's not cooperating for me today. I wasn't able to get a howdy to print, and the javascript still ran on page 2020.
    – Pat
    Commented Dec 16, 2012 at 21:48
  • I copied that whole block of code into my functions.php and it works as expected. Are you sure you are talking about a page and not a post?
    – s_ha_dum
    Commented Dec 16, 2012 at 21:52
  • Yeah, its listed under the Pages section. I'm also sure it's page 2020, since in the URL it shows post=2020&action=edit
    – Pat
    Commented Dec 16, 2012 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.