Skip to content

Instantly share code, notes, and snippets.

View jdevalk's full-sized avatar
😀

Joost de Valk jdevalk

😀
View GitHub Profile
@jdevalk
jdevalk / presstrends.php
Created August 15, 2012 19:37
Improved PressTrends tracking
<?php
/**
* PressTrends tracking
*/
function presstrends_plugin() {
// PressTrends Account API Key
$api_key = 'n6svrrn650hyckud8ghhs1o497hcm0g1o3s5';
$auth = 'dhs4fy3nhnx5x0y6gkdfwt7fz2wprguqk';
@jdevalk
jdevalk / regex.php
Created July 2, 2012 18:41
Regex to match meta description in content
<?php
preg_match_all( '#<meta (name|content)="(.*)" (name|content)="(.*)"(\s+)?/?>#i', $content, $matches, PREG_SET_ORDER );
preg_match_all( "#<meta (name|content)='(.*)' (name|content)='(.*)'(\s+)?/?>#i", $content, $matches2, PREG_SET_ORDER );
@jdevalk
jdevalk / non-ssl-redirect.php
Created June 20, 2012 18:14
WordPress code to redirect non-admin and non-login pages to http when opened over https
<?php
// If we're not on an admin or login page, make sure we're not on https.
if ( !is_admin() && strpos($_SERVER['REQUEST_URI'], 'login.php') === false && $_SERVER['HTTPS'] == 'on' ) {
wp_redirect( "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], 301 );
}
@jdevalk
jdevalk / fix-dupe-title-alts.php
Created June 15, 2012 13:22
If title attribute == alt attribute, strip title attribute.
<?php
if ( preg_match_all( '/<img [^>]+>/', $post->post_content, $matches ) ) {
$content_changed = false;
foreach ( $matches[0] as $img ) {
preg_match( '/title=("|\')([^"\']+)("|\') /', $img, $title_match );
preg_match( '/alt=("|\')([^"\']+)("|\') /', $img, $alt_match );
if ( isset($title_match[2]) && isset($alt_match[2]) && $title_match[2] == $alt_match[2] ) {
$post->post_content = str_replace( $title_match[0], '', $post->post_content );
@jdevalk
jdevalk / changelog-1.2.md
Created May 28, 2012 19:53
Changelog for WP SEO 1.2

If you want to help test, you can download the development version from here, or directly from here. If you find issues, please file them here.

= 1.2 (development version) =

Major improvements: all sorts of fixes to suggest and keyword check functionality which now should allow for non-ascii stuff, like Greek, Arabic, but even "weird" chars in western-European languages.

  • Bugs fixed:
    • ereg_replace != preg_replace ; in other words: alt and title tags for images in xml sitemap fixed.
    • Image size for OpenGraph now defaults to medium for thumbnail image.
    • Selecting a Facebook App as the admin of your site now actually works.
<?php
// catch some weird locales served out by WP.
$locales = array(
'ar'=> 'ar_ar',
'ca'=> 'ca_es',
'en'=> 'en_us',
'el'=> 'el_gr',
'et'=> 'et_ee',
'fi'=> 'fi_fi',
'ja'=> 'ja_jp',
@jdevalk
jdevalk / gist:2692707
Created May 14, 2012 08:29
rewrite fix
Index: wp-includes/rewrite.php
===================================================================
--- wp-includes/rewrite.php (revision 20781)
+++ wp-includes/rewrite.php (working copy)
@@ -1927,19 +1927,42 @@
}
/**
+ * Schedules a flush of the rewrite rules.
+ *
@jdevalk
jdevalk / gist:2426489
Created April 20, 2012 06:11
Search query
SELECT c.Content, c.Title, c.ID, c.CTID, c.RID, r.Sitename,
CASE WHEN c.Title LIKE '%conversion%' THEN 1 ELSE 0 END AS titlematch,
CASE WHEN c.Content LIKE '%conversion%' THEN 1 ELSE 0 END AS contentmatch,
MATCH (c.Title, c.Content) AGAINST ('conversion') AS relevance
FROM Chapters c LEFT JOIN Reviews r
ON c.RID = r.ID
WHERE MATCH(c.Title, c.Content) AGAINST ('conversion' IN BOOLEAN MODE)
HAVING relevance > 0
ORDER BY titlematch DESC, contentmatch DESC, relevance DESC
LIMIT 50
@jdevalk
jdevalk / pinterest.php
Created April 16, 2012 10:16
Pinterest button shortcode
<?php
// Usage [pin img="<url>" title="<title>"]
function yoast_pinterest_shortcode( $atts ) {
extract( shortcode_atts( array(
'url' => get_permalink(),
'img' => '',
'title' => get_the_title(),
'align' => 'alignright'
@jdevalk
jdevalk / links.php
Created March 28, 2012 17:33
Link template