Skip to content

Instantly share code, notes, and snippets.

/**
*
* Remove autoembed in frontend
*/
function ps_disable_autoembed(){
if ( ! is_admin() )
remove_filter( 'the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 );
}
@sophy
sophy / remove-empty-p.php
Created August 17, 2018 08:59 — forked from ninnypants/remove-empty-p.php
Remove empty p tags from WordPress posts
<?php
add_filter( 'the_content', 'remove_empty_p', 20, 1 );
function remove_empty_p( $content ){
// clean up p tags around block elements
$content = preg_replace( array(
'#<p>\s*<(div|aside|section|article|header|footer)#',
'#</(div|aside|section|article|header|footer)>\s*</p>#',
'#</(div|aside|section|article|header|footer)>\s*<br ?/?>#',
'#<(div|aside|section|article|header|footer)(.*?)>\s*</p>#',
'#<p>\s*</(div|aside|section|article|header|footer)#',
@sophy
sophy / Laravel on VestaCP.md
Created June 7, 2018 08:36 — forked from peterbrinck/Laravel on VestaCP.md
Laravel web templates for VestaCP

I've made a new web template to make Laravel work easily on VestaCP, and so I wouldn't have to change my Laravel installation, if I ever wanted to deploy it elsewhere.

Each file should be put in /usr/local/vesta/data/templates/web/apache2

Then, when you edit your domain/site, you can change the web template to Laravel and just upload your whole project into public_html

@sophy
sophy / chnage-vesta-port.txt
Created April 10, 2018 17:00
Change Port VestaCP to any port number
Step 1: Change port Vesta 8083 to 8485
sed -i 's/8083;/8485;/' /usr/local/vesta/nginx/conf/nginx.conf
Step 2: Add port 8485 to Firewal
/usr/local/vesta/bin/v-add-firewall-rule ACCEPT 0.0.0.0/0 8485 TCP gVestaCP
Step 3: Check port 8083 in firewal rules
sed -i -e '/8083/ s/ACCEPT/DROP/' /usr/local/vesta/data/firewall/rules.conf
@sophy
sophy / functions.php
Last active December 18, 2017 16:48 — forked from anonymous/functions.php
<?php
//----
/**
* Past this function into your theme file: functions.php
*/
function my_theme_tag_user_amanzon_tracking_id ( $tracking_id ) {
if ( is_single() ) {
$user_tag = get_the_author_meta('amazon-track');
@sophy
sophy / functions.php
Last active September 25, 2017 17:44
Add Extra Replacement Variables to Yoast SEO
<?php
//...
function theme_prefix_retrieve_short_month_year() {
return '('. date('M. Y') . ')';
}
function theme_prefix_register_short_month_year() {
wpseo_register_var_replacement( '%%currentshortmonthyear%%', 'theme_prefix_retrieve_short_month_year', 'advanced', 'Replaced with the current Month and Year (Sep. 2017)' );
@sophy
sophy / routing_patterns.php
Created July 13, 2016 05:23 — forked from lucasdavies/routing_patterns.php
Routing patterns from laravel-tricks.com
<?php
// This is what you might have right now
Route::get('users/{id}', 'UserController@getProfile')->where('id', '[\d+]+');
Route::get('products/{id}', 'ProductController@getProfile')->where('id', '[\d+]+');
Route::get('articles/{slug}', 'ArticleController@getFull')->where('slug', '[a-z0-9-]+');
Route::get('faq/{slug}', 'FaqController@getQuestion')->where('slug', '[a-z0-9-]+');
// and many more, now imagine you'll have to change the rule
// Instead, you could have a handy list of patterns and reuse them everywhere:
!-- Photo select
SELECT link, src, src_big,like_info, comment_info, caption FROM photo WHERE owner = 520708567985881 limit 4
!-- Video
SELECT link, vid, title,description,src,src_hq,length, embed_html,thumbnail_link FROM video WHERE owner = 520708567985881 limit 4
!-- Complex Video FQL
SELECT link, vid, title,description,src,src_hq,length, embed_html,thumbnail_link,created_time,updated_time FROM video WHERE owner IN (142178602466114,520708567985881,695311563831866)
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>FB Gload</title>
<link rel="stylesheet" href="css/fbgload.css">
<style>
#goald {
width: 100%;
}

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter