Skip to content

Instantly share code, notes, and snippets.

View rolandinsh's full-sized avatar
🧔
Remote developer (LEMP, Node.js, Neo4j [graph])

Rolands rolandinsh

🧔
Remote developer (LEMP, Node.js, Neo4j [graph])
View GitHub Profile
@rolandinsh
rolandinsh / gist:3259435
Created August 4, 2012 19:14
calculate date from day of year in php
<?php $todayid = date("z"); // to get today's day of year
function dayofyear2date( $tDay, $tFormat = 'd-m-Y' ) {
$day = intval( $tDay );
$day = ( $day == 0 ) ? $day : $day - 1;
$offset = intval( intval( $tDay ) * 86400 );
$str = date( $tFormat, strtotime( 'Jan 1, ' . date( 'Y' ) ) + $offset );
return( $str );
}
@rolandinsh
rolandinsh / gist:3263895
Created August 5, 2012 10:58 — forked from kloon/gist:2376300
WooCommerce Automatically add product to cart on site visit
/*
* goes in theme functions.php or a custom plugin
**/
// add item to cart on visit
add_action( 'init', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
global $woocommerce;
$product_id = 64;
$found = false;
@rolandinsh
rolandinsh / gist:3311580
Created August 10, 2012 06:04
wp get_query_var term get term info on Archive page
<?php
/*
via http://wordpress.stackexchange.com/a/15287/7577
codex: http://codex.wordpress.org/Function_Reference/get_query_var
*/
$termslug = get_query_var( 'term' );
$taxoname = get_query_var( 'taxonomy' );
$thisterm = get_term_by( 'slug', $termslug, $taxoname );
<?php
/**
* Google Analytics Integration http://www.phpkode.com/source/s/woocommerce/woocommerce/classes/integrations/google-analytics/class-wc-google-analytics.php
*
* Allows tracking code to be inserted into store pages.
*
* @class WC_Google_Analytics
* @package WooCommerce
* @category Integrations
* @author WooThemes
@rolandinsh
rolandinsh / gist:3510701
Created August 29, 2012 11:04
Do Not Track (DNT) detect with PHP code
function get_smc_dnt() {
/*
* Do Not Track for privacy.
* When this feature is enabled, webpage should exclude all tracking tools,
* like Google Analytic and advertising networks
*/
// returns TRUE if DNT is on and is equal to 1,
// returns FALSE if DNT is unset OR not equal to 1
return (isset($_SERVER['HTTP_DNT']) && $_SERVER['HTTP_DNT'] == 1);
}
@rolandinsh
rolandinsh / gist:3596401
Created September 2, 2012 10:07
.htaccess with/without www
RewriteEngine On
# with www
# RewriteCond %{HTTP_HOST} !^www\.
# RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# without www
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
@rolandinsh
rolandinsh / gist:3596420
Created September 2, 2012 10:09
PHP with/without www
<?php
/* redirect to with/without www version of page
* @date 2012-09-02
*/
if (substr($_SERVER['HTTP_HOST'],0,3) != 'www'){
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
}
<!--
based on:
* https://gist.github.com/3259153
* https://gist.github.com/3182211
Full information:
http://simplemediacode.com/wordpress-pugins/itemprop-wp/
-->
<span itemscope itemtype="http://schema.org/Article">
<!-- Itemprop WP 3.3.5 by Rolands Umbrovskis http://umbrovskis.com -->
<meta itemprop="name" content="Title of the Article" />
@rolandinsh
rolandinsh / gist:3721176
Created September 14, 2012 10:18
!WPSEO_VERSION
<?php
/* http://simplemediacode.info/snippets/better-page-title-with-and-without-yoast-wordpress-seo-plugin/ */
?>
<title>
<?php if (!defined('WPSEO_VERSION')) {
// if there is no WordPress SEO plugin activated
wp_title(' | ', true, 'right');
echo get_bloginfo('name')
.' '.get_bloginfo('description'); // or some WordPress default
}else {
@rolandinsh
rolandinsh / gist:3736133
Created September 17, 2012 08:14
Twitter feed with < em>
<!-- Twitter feed with < em> -->
<item>
<title>Es Tevi v&#x113;roju! http://t.co/yTu9nlFB</title>
<link>http://twitter.com/skatskat/statuses/247322950267699200</link>
<description>Es Tevi v&#x113;roju!&lt;em&gt; http:&lt;em&gt;/&lt;em&gt;/t.co/yTu9nlFB&lt;/em&gt;</description>
<pubDate>Sun, 16 Sep 2012 13:16:01 +0000</pubDate>
<guid>http://twitter.com/skatskat/statuses/247322950267699200</guid>
<author>skatskat@twitter.com (skatskat.lv 360&#xb0; )</author>
<media:content type="image/jpg" height="48" width="48" url="http://a0.twimg.com/profile_images/1150354480/ziarfe_80x80_normal.jpg"/>
<google:image_link>http://a0.twimg.com/profile_images/1150354480/ziarfe_80x80_normal.jpg</google:image_link>