Skip to main content
Removed snippet and included full code.
Source Link
Pat
  • 681
  • 2
  • 9
  • 29

Here's aEdit 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) {
   **Snipped code**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">
   **More snippeddocument.onkeydown code**= 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
}

Here's a snippet from the plugin:

if( is_single()) : ?>
<script type="text/javascript">    
   **Snipped code**
</script>
<?php elseif( is_home() || is_category()) : ?>
<script type="text/javascript">
   **More snipped code**
</script>
<?php endif;
}

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
}
Source Link
Pat
  • 681
  • 2
  • 9
  • 29

Exclude function from running on a certain page

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?

Here's a snippet from the plugin:

if( is_single()) : ?>
<script type="text/javascript">    
   **Snipped code**
</script>
<?php elseif( is_home() || is_category()) : ?>
<script type="text/javascript">
   **More snipped code**
</script>
<?php endif;
}