Skip to content

Instantly share code, notes, and snippets.

View kbcarte's full-sized avatar

K.B. Carte kbcarte

View GitHub Profile
@kbcarte
kbcarte / gf_us_to_top.php
Created February 11, 2026 20:38
Gravity Forms put USA at top of drop downs for countries, including drop down in Address field type
<?php
// Yoink: https://community.gravityforms.com/t/how-to-display-us-as-the-first-choice-but-leave-the-default-country-field-blank/17226/2
/**
* Set US to top of countries list in Gravity Forms.
*/
// Normal way
add_filter( 'gform_countries', 'modify_countries_list' );
@kbcarte
kbcarte / gravity_forms_country_dropdown.txt
Created February 11, 2026 17:22
Gravity Forms dropdown for Country with values
United States|US
Canada|CA
Afghanistan|AF
Aland Islands|AX
Albania|AL
Algeria|DZ
Andorra|AD
Angola|AO
Anguilla|AI
Antarctica|AQ
@kbcarte
kbcarte / gravity_forms_state-prov_dropdown.txt
Created February 11, 2026 17:13
Gravity Forms dropdown for State or Province with values
Alabama|AL
Alaska|AK
American Samoa|AS
Arizona|AZ
Arkansas|AR
California|CA
Colorado|CO
Connecticut|CT
Delaware|DE
District of Columbia|DC
@kbcarte
kbcarte / get_set_cookie.js
Created May 20, 2025 16:58
get_set_cookie.js
@kbcarte
kbcarte / get_page_post_ids.py
Created August 9, 2023 20:15
Goes through a csv of urls and meta info from RankMath export, the gets the post or page ID's of the page to update the exported report.
import requests, csv, time, re
from bs4 import BeautifulSoup
def get_page_id(url):
page = requests.get(url)
raw = page.text
soup = BeautifulSoup(raw, 'html.parser')
body = soup.find("body")
for i in body["class"]:
@kbcarte
kbcarte / which_wp_template.php
Created May 26, 2023 13:34
Show which php template WordPress is using, shows in the footer
<?php
// add to functions.php
// Yoink: https://wordpress.stackexchange.com/a/130921
function show_template() {
if( is_super_admin() ){
global $template;
print_r($template);
}
}
@kbcarte
kbcarte / blog_archive_template_ajax_pagination.php
Last active May 5, 2023 17:09
Page Template custom WP_Query with ajax and pagination
<?php
/*
Template Name: Blog Archive
Author: kbcarte
*/
get_header();
?>
<?php
// Yoink https://wordpress.stackexchange.com/a/154364
if ( ! function_exists( 'pagination' ) ) {
function pagination( $paged = '', $max_page = '' ) {
$big = 999999999; // need an unlikely integer
if( ! $paged ) {
$paged = get_query_var('paged');
}
@kbcarte
kbcarte / canonical_remove_trailing_slash.php
Created April 3, 2023 15:42
Remove the trailing slash from the canonical meta link form Yoast SEO
<?php
/* Place in functions.php */
function prefix_filter_canonical_example( $canonical ) {
if ( substr( $canonical, -1 ) == "/" ) {
return substr($canonical, 0, -1);
}
return $canonical;
}
add_filter( 'wpseo_canonical', 'prefix_filter_canonical_example' );
@kbcarte
kbcarte / insert_locations.php
Created November 3, 2022 14:38
Insert new location pages based on array of city names
<?php
// example of FL
$imports = array('Brooksville','Spring Hill','New Port Richey','Hudson','Port Richey','Holiday','Dade City','Zephyrhills','Wesley Chapel','San Antonio','Kathleen','Webster','Saint Petersburg','Clearwater','Clearwater Beach','Largo','Seminole','Pinellas Park','Palm Harbor','Tarpon Springs','Safety Harbor','Dunedin','Odessa','Lutz','Tampa','Land O Lakes','Thonotosassa','Plant City','Lakeland','Auburndale','Bartow','Eagle Lake','Mulberry','Winter Haven','Brandon','Dover','Gibsonton','Lithia','Riverview','Ruskin','Apollo Beach','Sun City Center','Seffner','Valrico','Wimauma','Palmetto');
foreach( $imports as $i ){
$page_id = wp_insert_post(
array(
'comment_status' => 'close',
'ping_status' => 'close',