Skip to content

Instantly share code, notes, and snippets.

@tyohan
tyohan / functions.php
Created November 14, 2017 07:57
Functions to make scripts async and defer on WordPress Seventeen Theme
function add_defer_attribute($tag, $handle) {
// add script handles to the array below
$scripts_to_defer = array(
'html5',
'jquery',
'jquery-migrate',
'wp-embed',
'twentyseventeen-skip-link-focus-fix',
'jquery-scrollto',
'twentyseventeen-global',
@lukecav
lukecav / functions.php
Created November 8, 2017 21:39
Display full site URL in WordPress
echo get_site_url();
@lukecav
lukecav / wp-config.php
Created November 7, 2017 18:59
Disable `edd_items_in_cart` cookie if using Easy Digital Downloads
define( 'EDD_USE_CART_COOKIE', false );
@varundevpro
varundevpro / tags-in-head.md
Last active February 18, 2026 14:51
A list of everything that could go in the <head> of your document

HEAD

CC0 Contributors

A list of everything that *could* go in the <head> of your document

Table of Contents

@mikaelz
mikaelz / class-pie-wcwl-waitlist-mailout.php
Created November 2, 2017 12:27
Fix waitlist allowed memory limit error
diff --git a/wp-content/plugins/woocommerce-waitlist/classes/class-pie-wcwl-waitlist-mailout.php b/wp-content/plugins/woocommerce-waitlist/classes/class-pie-wcwl-waitlist-mailout.php
index e77ed03..2e41933 100644
--- a/wp-content/plugins/woocommerce-waitlist/classes/class-pie-wcwl-waitlist-mailout.php
+++ b/wp-content/plugins/woocommerce-waitlist/classes/class-pie-wcwl-waitlist-mailout.php
@@ -83,6 +83,9 @@ if ( ! class_exists( 'Pie_WCWL_Waitlist_Mailout' ) ) {
public function add_user_to_archive( $product_id, $user_id ) {
$existing_archives = get_post_meta( $product_id, 'wcwl_waitlist_archive', true );
$today = strtotime( date( "Ymd" ) );
+ if (empty($existing_archives)) {
+ $existing_archives = array();
@tigran-sn
tigran-sn / excerpt.php
Created November 1, 2017 11:46
Limit Post Excerpt Length Using Number Of Words
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`[[^]]*]`','',$excerpt);
return $excerpt;
@ihorduchenko
ihorduchenko / plugins.wp-config.php
Created October 31, 2017 07:00
Allow wordpress to install plugins on local machine
//Insert in wp-config.php file
define('FS_METHOD','direct');define('FS_CHMOD_DIR',0755);define('FS_CHMOD_FILE',0644);
define('WP_TEMP_DIR',dirname(__FILE__).'/wp-content/uploads');
@Shumaher
Shumaher / header.php
Last active April 24, 2018 14:42
Open Graph tags for WordPress, see http://blog.alexz.me/wp-opengraph for more info
<head>
<?php if (is_single() || is_page()) { ?>
<meta name="description" content="<?php $s = trim(str_replace("\r\n", " ", htmlspecialchars(strip_tags($post->post_content)))); if(mb_strlen($s,'UTF-8') > 200){$postdescr = mb_substr($s,0,198,'UTF-8').' …';} else{$postdescr = $s;}; echo $postdescr; ?>" />
<meta property="og:description" content="<?php echo $postdescr; ?>" />
<meta property="og:url" content="http://site.com/<?php global $post; echo $post->post_name; ?>" /> <!-- OR -->
<meta property="og:url" content="<?php the_permalink() ?>" />
<meta property="og:title" content="Site Name<?php wp_title(); ?>" />
<meta property="og:headline" content="Site Name<?php wp_title(); ?>" />
<?php if (get_post_meta($post->ID, 'image_id', true)){$postimage = wp_get_attachment_image_src(get_post_meta($post->ID, 'image_id', true), 'full'); ?>
<link rel="image_src" href="<?php echo $postimage[0]; ?>" />
@bhubbard
bhubbard / functions.php
Created October 27, 2017 18:43 — forked from lukecav/functions.php
Stop WordPress sending anything but essential data during the update check
function wp_update_privacy( $query ) {
unset($query['php']);
unset($query['mysql']);
unset($query['local_package']);
unset($query['blogs']);
unset($query['users']);
unset($query['multisite_enabled']);
unset($query['initial_db_version']);
return $query;
}
@ccurtin
ccurtin / add-yoast-seo-data-to-WP-REST-API.php
Created October 27, 2017 17:49
Add 'yoast' SEO data to the REST API w/ og & twitter meta fallbacks...
<?php
/*
Creates and end-point that get Yoast SEO meta tags...
*/
add_action('rest_api_init', 'add_yoast_data');
function add_yoast_data()
{
// Add your post types here...
register_rest_field(array(