Skip to content

Instantly share code, notes, and snippets.

@jamesmthornton
jamesmthornton / facetwp.template-and-query
Created December 19, 2022 19:55
FacetWP Troubleshooting 12-19-2022 Template and Query
<?php
// query args generated
return [
"post_type" => [
"cases"
],
"post_status" => [
"publish"
],
@jamesmthornton
jamesmthornton / console.log
Created December 19, 2022 19:51
FacetWP Troubleshooting 12-19-2022
{
"query_args": {
"post_type": [
"post"
],
"post_status": [
"publish",
"acf-disabled"
],
"author": "2",
@jamesmthornton
jamesmthornton / functions.php
Created December 9, 2021 15:44
add reusable blocks to wp admin
add_action( 'admin_menu', 'add_wp_blocks_to_menu' );
function add_wp_blocks_to_menu(){
global $menu;
add_menu_page( 'global_blocks', 'Global Blocks', 'read', 'wp_block', '', 'dashicons-align-right', 1 );
$menu[1][2] = "/wp-admin/edit.php?post_type=wp_block";
}
// https://indiyoung.wpengine.com/wp-admin/edit.php?post_type=wp_block
@jamesmthornton
jamesmthornton / functions.php
Created October 13, 2021 14:21
WP check image sizes
<?php
// check default image sizes
print_r( get_intermediate_image_sizes() );
// check registered image sizes
global $_wp_additional_image_sizes;
print_r( $_wp_additional_image_sizes ); ?>
@jamesmthornton
jamesmthornton / Appearance > Themes > Theme Editor > functions.php
Last active July 22, 2021 12:31
wordpress function to output meta tag for domain verification in head
add_action('wp_head','ifjt_meta_domain_verify');
function ifjt_meta_domain_verify() {
?>
<meta name="facebook-domain-verification" content="67up5r2pygsmvi3sjhya25ab6m0jg3" />
// replace this line with a meta verification code
<?php
}
@jamesmthornton
jamesmthornton / gds-custom-channel-grouping.sql
Created December 5, 2020 13:57
Google Data Studio > Custom Field Formula > Google Analytics Connector > Custom Channel Grouping
CASE
WHEN ( CONTAINS_TEXT(Source / Medium, "(direct) / (none)") OR CONTAINS_TEXT(Source / Medium, "none") ) THEN "Direct"
WHEN ( CONTAINS_TEXT(Campaign,"email") OR CONTAINS_TEXT(Source / Medium, "email") ) THEN "Email"
WHEN ( CONTAINS_TEXT(Source / Medium,"affiliate") OR CONTAINS_TEXT(Source / Medium, "shareasale") ) THEN "Affiliates"
WHEN ( CONTAINS_TEXT(Source / Medium,"display") OR CONTAINS_TEXT(Source / Medium, "taboola") ) THEN "Display Ads"
WHEN ( CONTAINS_TEXT(Source / Medium,"organic") OR CONTAINS_TEXT(Source / Medium, "baidu") ) THEN "Organic Search"
WHEN ( CONTAINS_TEXT(Source / Medium,"google / cpc") OR
CONTAINS_TEXT(Source / Medium, "adwords") OR
CONTAINS_TEXT(Source / Medium, "googleadservices.com / referral") OR
CONTAINS_TEXT(Source / Medium, "Google / Ad")
@jamesmthornton
jamesmthornton / functions.php
Last active July 25, 2020 18:47
Add a link to the edit reusable blocks page in Wordpress dashboard UI
<?php
add_action( 'admin_menu', 'add_wp_blocks_to_menu' );
function add_wp_blocks_to_menu(){
global $menu;
add_menu_page( 'global_blocks', 'Global Blocks', 'read', 'wp_block', '', 'dashicons-align-right', 1 );
$menu[1][2] = "/wp-admin/edit.php?post_type=wp_block";
}
@jamesmthornton
jamesmthornton / myDivsNoClasses.js
Last active July 10, 2020 21:18
Remove tags, class attributes and attribute contents from DOM
// Remove all class attributes and contents from divs in the DOM
var myDivs = document.getElementsByTagName('div'); // replace div with span for spans
for (var i = 0; i < myDivs.length; i++) {
myDivs[i].removeAttribute('class'); // replace class with any attribute you want stripped out
}
// Remove all SVGs from the DOM
var collectSvg = document.getElementsByTagName('svg');
for (var i = 0; i < collectSvg.length; i++) {
collectSvg[i].parentNode.removeChild(collectSvg[i]);
@jamesmthornton
jamesmthornton / remove-start-of-title.sql
Created June 25, 2020 20:37
Remove a prepended constant from post titles in Wordpress
-- this would remove the following string including a trailing space: [PMC Daily Insight]
UPDATE wp_posts
SET post_title =
MID( post_title, LENGTH('[PMC Daily Insight] ')+1 )
WHERE post_title LIKE '[PMC Daily Insight] %'
AND post_type = 'post';
@jamesmthornton
jamesmthornton / functions.php
Last active June 24, 2020 23:48
Prepend a CTA to your RSS feed body/content or text to your subject line
<?php
// prepend a call to action to your email body by adding before your the_content()
function prepend_rss_cta($content) {
$cta = ' <p><i>Want to share or link to this post? It lives here: <a href="' . get_the_permalink( get_the_ID() ). '">' . get_the_title( get_the_ID() ) . '</a>.</i></p>';
$content = $cta . $content; // switch cta and content to append (not prepend) your CTA
return $content;
}
add_filter('the_content_feed', 'prepend_rss_cta');