Responsive Adsense Plugin for WordPress

Responsive Adsense Plugin

I recently posted about a way to display different sizes of adverts depending on the window size. I’m sure it could be useful for a lot of people, so… I made it a WordPress plugin.

It’s a simple widget that works with your Google Adsense “Publisher ID” and some of your Advert Units IDs.

It will display on your pages the bigger unit that can fit in the widget container.

Enjoy folks !

Add a custom class to every WordPress Widgets

function myclass_dynamic_sidebar_params( $params ) {
	$myclass = 'myclass';
	$params[0]['before_widget'] = preg_replace( '/class="/', 'class="' . $myclass . ' ', $params[0]['before_widget'], 1 );
	return $params;
}
add_filter( 'dynamic_sidebar_params', 'myclass_dynamic_sidebar_params' );

Convert SVG relative path data to absolute polyline points with JavaScript

This function return an array of the different absolute paths received as a string, converted to absolute points.

function pathToPoints( path ) {
  var paths = path.split( /z|Z/ ), points = new Array();
  for ( var i = 0; i < paths.length-1; i++ ) {
    path = paths[i].split( /l|L/ );
    path[0] = path[0].replace( /m|M/, '' );
    for ( var j in path ) {
      path[j] = path[j].split( ',' );
      for ( var k in path[j] ) {
        path[j][k] = parseFloat( path[j][k] );
        if ( j != 0 ) {
          path[j][k] += path[j-1][k];
        }
      }
    }
    for ( var j in path ) {
      path[j] = path[j].join( ',' );
    }
    points[i] = path.join( ' ' );
  }
  return points;
}

Function get_term_parents() for WordPress

function get_term_parents( $id, $taxonomy, $link = false, $separator = '/', $nicename = false, $visited = array() ) {
  $chain = '';
  $parent = &get_term( $id, $taxonomy );
  if ( is_wp_error( $parent ) )
    return $parent;
  if ( $nicename )
    $name = $parent->slug;
  else
    $name = $parent->name;
  if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
    $visited[] = $parent->parent;
    $chain .= get_term_parents( $parent->parent, $taxonomy, $link, $separator, $nicename, $visited );
  }
  if ( $link )
    $chain .= '<a href="' . esc_url( get_term_link( intval( $parent->term_id ), $taxonomy ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator;
  else
    $chain .= $name.$separator;
  return $chain;
}