Skip to content

Instantly share code, notes, and snippets.

View juniormiranda89's full-sized avatar

Junior Miranda juniormiranda89

View GitHub Profile
@aahan
aahan / WordPress Custom Global Variables.md
Last active March 28, 2024 19:26
Creating and using custom global variables in wordpress.

First create global variables (in functions.php or as a mu-plugin):

<?php

/*
 * CUSTOM GLOBAL VARIABLES
 */
function wtnerd_global_vars() {
@quawn
quawn / function.php
Last active April 11, 2024 22:22
WP: Check if image attached to the post
<?php
$attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image') );
if ( $attachments ) {
// do conditional stuff here
}
@JulienBlancher
JulienBlancher / filter.d_nginx-auth.conf
Last active July 14, 2024 19:32
Fail2ban Config with Nginx and SSH
#
# Auth filter /etc/fail2ban/filter.d/nginx-auth.conf:
#
# Blocks IPs that makes too much accesses to the server
#
[Definition]
failregex = ^<HOST> -.*"(GET|POST).*HTTP.*"
ignoreregex =
@v0lkan
v0lkan / nginx.conf
Last active July 12, 2024 08:28
Configuring NGINX for Maximum Throughput Under High Concurrency
user web;
# One worker process per CPU core.
worker_processes 8;
# Also set
# /etc/security/limits.conf
# web soft nofile 65535
# web hard nofile 65535
# /etc/default/nginx
@Nils-Fredrik
Nils-Fredrik / gist:dde97d0e5c7b8020de08aed948eab59f
Created April 2, 2016 18:15
array_filter and strlen to filter array
<?php
$array = array(
0,
'',
false,
1,
'0'
);
print_r( $array );
print_r( array_filter( $array, 'strlen' ) );
@adamzr
adamzr / .htaccess
Created May 24, 2016 21:33
Add Link headers to preload content
<IfModule mod_headers.c>
Header add Link "</service-worker.js>; rel=preload;"
Header add Link "</favicon-16x16.png>; rel=preload;"
Header add Link "</favicon-96x96.png>; rel=preload;"
Header add Link "</android-chrome-192x192.png>; rel=preload;"
Header add Link "<https://cdn.ampproject.org/v0.js>; rel=preload; crossorigin"
Header add Link "<https://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface>; rel=preload; crossorigin"
Header add Link "<https://cdn.ampproject.org/v0/amp-analytics-0.1.js>; rel=preload; crossorigin"
Header add Link "<https://cdn.ampproject.org/v0/amp-install-serviceworker-0.1.js>; rel=preload; crossorigin"
Header add Link "<https://fonts.gstatic.com/s/abrilfatface/v8/X1g_KwGeBV3ajZIXQ9VnDgYWpCd0FFfjqwFBDnEN0bM.woff2>; rel=preload; crossorigin"
@hirejordansmith
hirejordansmith / insert-content-wordpress-after-certain-amount-paragraphs.php
Created December 6, 2016 13:59
Insert Content in WordPress after a certain amount of paragraphs
<?php
//Insert ads after second paragraph of single post content.
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
$ad_code = '<div>Ads code goes here</div>';
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $ad_code, 2, $content );
}
return $content;
}
@goranseric
goranseric / gist:f00c2e485584d2dbb57b947a1259095e
Created January 23, 2017 13:11
WP - Require featured image
<?php
/**
* Require a featured image to be set before a post can be published.
*/
add_filter( 'wp_insert_post_data', function ( $data, $postarr ) {
$post_id = $postarr['ID'];
$post_status = $data['post_status'];
@sabrina-zeidan
sabrina-zeidan / delete_tags_with_no_posts.php
Created July 22, 2017 14:59
Bulk delete tags with no posts (posts only check, may probable have cpt attached) [Wordpress]
function delete_tags_with_no_posts(){
$tags = get_tags( array('number' => 0,'hide_empty' => false));
foreach ( $tags as $tag ) {
$tag_id = $tag->term_id;
$args = array( 'post_type' => 'post', 'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'post_tag',
'field' => 'id',
'terms' => $tag_id
@sabrina-zeidan
sabrina-zeidan / delete_empty_tags.php
Created July 22, 2017 15:00
Bulk delete unused tags [Wordpress]
function delete_empty_tags(){
$tags = get_tags( array('number' => 0,'hide_empty' => false));
foreach ( $tags as $tag ) {
$tag_count = $tag->count;
if ($tag_count < 1 ){
wp_delete_term( $tag->term_id, 'post_tag' );
}
}
}
add_action( 'wp_head', 'delete_empty_tags' );