Skip to content

Instantly share code, notes, and snippets.

View kbcarte's full-sized avatar

K.B. Carte kbcarte

View GitHub Profile
@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',
@kbcarte
kbcarte / disable_xmlrpc.php
Created September 23, 2022 13:56
WordPress filter to remove XML-RPC functionality, add this to functions.php
<?php
add_filter( ‘xmlrpc_enabled’, ’_return_false’ );
@kbcarte
kbcarte / disable_comments.php
Last active August 23, 2022 13:57
WordPress disable all commenting.
<?php
/*
Force disable all commenting in WordPress
Place this in your functions.php file
Yoink: https://gist.github.com/mattclements/eab5ef656b2f946c4bfb
*/
add_action('admin_init', function () {
// Redirect any user trying to access comments page
global $pagenow;
@kbcarte
kbcarte / FZ_dont_use_keys.md
Created August 22, 2022 14:23
FileZilla FATAL ERROR type 11 WPEngine fix

The issue is, on Ubuntu, FileZilla is trying multiple ssh keys even when set to use username/pass for sftp connections. This causes WPEngine to drop the connection after the first one or two attempts with bad keys.

To fix this, we can set the SSH_AUTH_SOCK env variable before launching filezilla. This does require opening FileZilla from the cli, but we can make an alias for it.

In my .bashrc file, I add this alias at the end.

  • alias fz="SSH_AUTH_SOCK=null filezilla &"

Now the cli command fz will open FileZilla and work as expected.

@kbcarte
kbcarte / mp42webm.sh
Last active July 26, 2022 14:32
Use ffmpeg to convert mp4 videos to webm with better keyframe spacing for smooth scroll animations.
# OG Yoink: https://stackoverflow.com/a/33855249
# -g 8, was chosen based on this: https://docs.microsoft.com/en-us/windows/win32/wmformat/configuring-video-streams-for-seeking-performance?redirectedfrom=MSDN
ffmpeg -i input_video.mp4 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis -g 8 output_video.webm;