Skip to content

Instantly share code, notes, and snippets.

@JTruax
JTruax / wp-snippets.php
Last active June 29, 2023 17:54
WordPress Function Snippets
<!--------------------------------------------------------
SNIPPETS INDEX
-- 01 - Enqueue Google Fonts
-- 02 - Make jQuery load from Google Library
-- 03 - Customize excerpt length and read more characters
-- 04 - Enable Pagination Links
-- 05 - Replace WP login logo with custom
-- 06 - Displays a custom Dashboard Widget
-- 07 - Allow different file formats in Media Library
-- 08 - Turn Off Your Self-referring Pingbacks
@holmberd
holmberd / php-pools.md
Last active April 19, 2024 07:24
Adjusting child processes for PHP-FPM (Nginx)

Adjusting child processes for PHP-FPM (Nginx)

When setting these options consider the following:

  • How long is your average request?
  • What is the maximum number of simultaneous visitors the site(s) get?
  • How much memory on average does each child process consume?

Determine if the max_children limit has been reached.

  • sudo grep max_children /var/log/php?.?-fpm.log.1 /var/log/php?.?-fpm.log
@hnq90
hnq90 / functions.php
Created January 11, 2018 16:52 — forked from yoren/functions.php
Parent Post From Another Post Type And A New URL Structure In WordPress
<?php
// Flush rewrite rules after switch theme
function my_rewrite_flush() {
flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'my_rewrite_flush' );
// A little help so we can get the stylesheet from parent theme
// Remove line 10-19 if this is not a child theme
function my_enqueue_styles() {
@mkg20001
mkg20001 / generate-nginx-cloudflare-allow.sh
Last active April 5, 2024 07:41
A script to generate a config to allow or additionally allow cloudflare addresses for a specific domain
#!/bin/bash
set -e
cf_ips() {
echo "# https://www.cloudflare.com/ips"
for type in v4 v6; do
echo "# IP$type"
curl -sL "https://www.cloudflare.com/ips-$type/" | sed "s|^|allow |g" | sed "s|\$|;|g"
@wplit
wplit / style.css
Last active February 14, 2022 07:23
Allow tabbing across the sub menu items in Oxygen Menu (for keyboard user)
/* Allows focus on sub menu items by tabbing menu
------------------------------------------------ */
.oxy-nav-menu:not(.oxy-nav-menu-open) .menu-item .sub-menu {
right: 5000px;
visibility: visible;
}
.oxy-nav-menu:not(.oxy-nav-menu-open).menu-item .sub-menu .sub-menu {
right: auto;
@soderlind
soderlind / get-ip.php
Last active July 12, 2021 09:14
PHP, Get IP behind trusted proxy
<?php
/**
* Inspired by https://raw.githubusercontent.com/zendframework/zend-http/master/src/PhpEnvironment/RemoteAddress.php
*/
//PHP 5.6
function get_ip( $trusted_proxies = [] ) {
if ( ! empty( $trusted_proxies ) && isset( $_SERVER['REMOTE_ADDR'] ) && ! in_array( $_SERVER['REMOTE_ADDR'], $trusted_proxies ) ) {
if ( isset( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) {
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
} elseif ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) {
@ulziibat-n
ulziibat-n / wpseo_schema_organization.php
Created September 10, 2019 14:14 — forked from nicomollet/wpseo_schema_organization.php
Yoast SEO Organization Schema Replaced By LocalBusiness
<?php
/**
* Add LocalBusiness to schema Organization
*
* @api array $data The graph piece to filter.
*
* @return array
*/
function custom_wpseo_schema_organization($data){
@lubieowoce
lubieowoce / yoast_coauthors_integration.php
Last active June 1, 2023 01:17
Integrate Yoast with CoAuthors Plus
<?php
// Written against:
// - Yoast SEO 12.3
// - Co-Authors Plus 3.4
// - Wordpress 4.9.3
// - PHP 7.1
/*
@yankiara
yankiara / oxygen-repeater-dynamic-query.php
Last active September 6, 2023 19:25
Use dynamic queries with Oxygen's repeater
/* I'll put here different examples of dynamic query for Oxygen repeater :
* - Use one of the following repeater_dynamic_query definitions
* in code block just BEFORE the repeater
* - Set the repeater custom query settings : post type, number of posts, order...
* - Add the remove_action in a code block AFTER the repeater
*/
/****************************************************************************************************
* Display related posts for any CPT with taxonomy:
@ThatGuySam
ThatGuySam / allowed-block-types.php
Last active October 31, 2023 08:06
Limit allowed Gutenberg Blocks with full list of native Wordpress Blocks
<?php
// Hook up function to allowed_block_types filter
add_filter( 'allowed_block_types', 'set_allowed_block_types' );
/**
* Set allowed gutenburg block types
* https://rudrastyh.com/gutenberg/remove-default-blocks.html
*/