Skip to content

Instantly share code, notes, and snippets.

View kbcarte's full-sized avatar

K.B. Carte kbcarte

View GitHub Profile
@kbcarte
kbcarte / upload-set-featured-image.php
Created July 19, 2022 14:49
Wordpress function to upload and set a posts featured image with php.
@kbcarte
kbcarte / functions.php
Created June 27, 2022 15:21
WordPress show page template being used
<?php
// Yoink: https://mekshq.com/which-wordpress-template-file-used/
//For example, you can paste this into your theme functions.php file
function meks_which_template_is_loaded() {
if ( is_super_admin() ) {
global $template;
print_r( $template );
}
}
@kbcarte
kbcarte / functions.php
Last active November 22, 2023 20:34
WordPress insert into head and body (GTAG, Analytics)
<?php
// Insert code snippits to the <head> and <body> tags
// Useful for gtag and analytics
function insert_in_head() {
?>
<!-- Google Tag Manager -->
<!-- SCRIPT FOR GTAG -->
<!-- End Google Tag Manager -->
@kbcarte
kbcarte / google_font_weight_conversion.md
Last active June 17, 2022 18:04
Google font weight conversion
@kbcarte
kbcarte / find-contact-form-7.md
Created May 6, 2022 15:36
Find all posts and pages in WordPress containing contact form 7

For ALL contact form 7

SELECT `guid`, `post_title` FROM `wp_posts` WHERE `post_content` LIKE '%[contact-form-7%'

For contact form 7 form by ID

Replace <ID HERE> with the id number found in wp-admin

SELECT `guid`, `post_title` FROM `wp_posts` WHERE `post_content` LIKE '%[contact-form-7 id="<ID HERE>"%'
@kbcarte
kbcarte / update_yoast_index.md
Last active August 23, 2022 14:05
Update all pages/posts Yoast SEO Advanced settings to be index by google

Update all pages/posts to be index by google. This is a global update and will set all posts/pages to be indexed.

UI found in post/page in the Yoast SEO setction, under Advanced

Run this query in phpmyadmin, adminer, or what ever db client you are using.

UPDATE `wp_postmeta` SET `meta_value`='2' WHERE `meta_key`='_yoast_wpseo_meta-robots-noindex'
@kbcarte
kbcarte / disk_usage.md
Last active April 6, 2022 18:48
ssh view disk usage

To view disk usage via cli.

$ df -h --total

Example Output:

Filesystem      Size  Used Avail Use% Mounted on
udev            992M     0  992M   0% /dev
tmpfs           201M   23M  178M  12% /run
/dev/vda7 50G 39G 8.6G 82% /
@kbcarte
kbcarte / wp-rocket_cli.md
Created April 6, 2022 15:27
Install wp-rocket cli and import a previously exported json settings file.

wp cli is usually installed as just wp, but sometimes you may find it called wp-cli instead.

/path/to/wp-rocket-settings-backup.json is the exported json file from wp-rocket. Replace with the path and file name of the json file on your server or cluster.

  • $ wp package install --allow-root wp-media/wp-rocket-cli:trunk
  • $ wp rocket import --file=/path/to/wp-rocket-settings-backup.json
@kbcarte
kbcarte / reset-node_moduels.md
Created March 30, 2022 18:45
nuke node_modules and go again
$ sudo rm -rf package-lock.json node_modules
$ sudo npm cache clean --force
$ npm install
@kbcarte
kbcarte / find-gravity-forms.md
Last active April 4, 2022 15:52
Find all posts and pages in WordPress containing gravity forms

For ALL gravity forms

SELECT `guid`, `post_title` FROM `wp_posts` WHERE `post_content` LIKE '%[gravityform%'

For gravity form by ID

Replace <ID HERE> with the id number found in wp-admin

SELECT `guid`, `post_title` FROM `wp_posts` WHERE `post_content` LIKE '%[gravityform id="<ID HERE>"%'