Instantly share code, notes, and snippets.

View manage_paragraphs.php
<?php
// Grab the first paragraph, show it where you need it, then take the rest of the content and remove the first paragraph and show it elsewhere
// The script uses WordPress functions/content but can be used in any PHP script, just replace the WP functions
// First Paragraph
global $post;
$p1 = wpautop( $post->post_content );
$p1 = substr( $p1, 0, strpos( $p1, '</p>' ) + 4 );
//$p1 = strip_tags($p1, '<a><strong><em><h3><h2><i>'); // in case you need to remove some tags, add the ones you want to KEEP here
View random_masonry.js
$('.grid').isotope({
itemSelector: '.grid-item',
//percentPosition: true,
masonry: {
columnWidth: 100
}
})
View wp_scripts.php
<?php
// Place the handles somewhere convenient
global $scripts_to_defer, $scripts_to_async, $scripts_origin;
$scripts_to_defer = array('fancybox_js', 'bootstrap_js');
$scripts_to_async = array('fontawesome_js');
$scripts_origin = array('fontawesome_js');
// Put this in functions.php
function add_defer_attribute($tag, $handle) {
View woo_remove_product_tags.php
<?php
// Overwrite product_tag taxonomy properties
add_action('init', function() {
register_taxonomy('product_tag', 'product', [
//'public' => false, // making it not public could throw errors in some themes / plugins
'show_ui' => false,
'show_admin_column' => false,
'show_in_nav_menus' => false,
'show_tagcloud' => false,
View gdpr_scripts.php
<?php
/* --------------------------------------------------------------------------------
*
* JS stand-alone (CSS not included - Get it here https://pastebin.com/uNKPdMVj)
*
-------------------------------------------------------------------------------- */
?>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
View expires.conf
# etc/httpd/conf.d/expires.conf
# https://support.plesk.com/hc/en-us/articles/115001711985-How-to-enable-leverage-browser-caching-in-Plesk
# https://support.plesk.com/hc/en-us/articles/213380049-How-to-enable-gzip-compression-on-nginx-on-Plesk-server
LoadModule expires_module modules/mod_expires.so
ExpiresActive on
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
View wc-custom_attributes.php
<?php
/* ------------------------------------------------------------------------------------------------
*
* METHOD 1
*
-------------------------------------------------------------------------------------------------- */
// Customize WooCommerce Attributes (method 1 - no swatches/plugins)
function wc_custom_attr( $product ) {
View wp_wc_filter_by_featured_product.php
View wp_get_og_img.php
<?php
// Get an image for Open Graph - Uses WP Imager https://github.com/Jany-M/WP-Imager
if(is_singular()) {
global $post;
if(function_exists('wp_imager')) {
$img = wp_imager(1200, 630, 1, '', '', '', true );
} elseif(has_post_thumbnail($post->ID)) {
$img = get_the_post_thumbnail_url( $post->ID, array(1200,630));
}
} else {
View wp_add_body_classes.php
<?php
function add_classes_to_body($classes) {
global $post;
// User Role
$user_info = get_currentuserinfo();
$classes[] = implode(' ', $user_info->roles);
// WPML
if ( function_exists('icl_object_id') ) {