Add a class to the first li.pager-item for a view pager? How can I add a class to the first li.pager-item and a different class to the last li.pager-item for for a Views pager? 

I know that I need to make a theme override of theme_pager
https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7

However I cant figure out what PHP to change.
If you implement theme_pager you'll be expected to create the entire pager render array from scratch using several theme function - theme_pager_first, theme_pager_previous, theme_pager_next and theme_pager_last. That seems like entirely too much work for adding one class.

Since theme_pager calls theme_item_list at the very end to build the final render array, you can use hook_preprocess_HOOK to modify the pager render array before drupal renders it into HTML.

function THEME_preprocess_item_list(&amp;$vars) {
  // make sure we're dealing with a pager item list
  if (isset($vars['attributes']['class']) &amp;&amp; in_array('pager', $vars['attributes']['class'])) {
    // make sure there are items
    if (count($vars['items'])) {
      $vars['items'][0]['class'][] = 'test';
    }
  }
}


Clear the cache after adding this hook.

UPDATE: find the first li.pager-item:

function THEME_preprocess_item_list(&amp;$vars) {
  // make sure we're dealing with a pager item list
  if (isset($vars['attributes']['class']) &amp;&amp; in_array('pager', $vars['attributes']['class'])) {
    // loop the items and find the first .pager-item
    foreach ($vars['items'] as $index =&gt; $item) {
      if (in_array('pager-item', $item['class'])) {
        $vars['items'][$index]['class'][] = 'test';
        break;
      }
    }
  }
}


UPDATE2: find first and last li.pager-item:

function THEME_preprocess_item_list(&amp;$vars) {
  // make sure we're dealing with a pager item list
  if (isset($vars['attributes']['class']) &amp;&amp; in_array('pager', $vars['attributes']['class'])) {

    // loop the items and find the first and last .pager-item
    $first = FALSE;
    $last = NULL;
    foreach ($vars['items'] as $index =&gt; $item) {
      if (in_array('pager-item', $item['class'])) {

        // first
        if (!$first) {
          $vars['items'][$index]['class'][] = 'test';
          $first = TRUE;
        }

        // last
        $last = $index;
      }
    }

    if (!empty($last)) {
      $vars['items'][$last]['class'][] = 'test2';
    }
  }
}