Skip to content

Instantly share code, notes, and snippets.

🐞
Debugging

Jon Fuller Garconis

View GitHub Profile
@Garconis
Garconis / translate-string-with-function.php
Last active Mar 22, 2019
WordPress | Translate string with PHP function
View translate-string-with-function.php
<?php
// option 1, to change text site wide
add_filter( 'gettext', 'fs_translate_strings_1', 20, 3 );
function fs_translate_strings_1( $translation, $text, $domain ) {
// STRING 1
$translation = str_ireplace( 'My Old Text', 'My New Text', $translation );
// STRING 2
$translation = str_ireplace( 'Old Text', 'New text', $translation );
return $translation;
@Garconis
Garconis / wp-config.php
Created Mar 8, 2019
WordPress | debug PHP by enabling WP_DEBUG log file in WP Config
View wp-config.php
<?php // remove this line
// add this to your wp-config.php file, before /* That's all, stop editing! Happy blogging. */
define( 'WP_DEBUG', true );
if (WP_DEBUG) {
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors',0);
}
@Garconis
Garconis / tml-change-lost-password-page-if-on-certain-url.php
Created Mar 4, 2019
Theme My Login | Shortcodes to spit out a custom Logout anchor and Helpers to force-change the Lost Password URL for certain pages/forms.
View tml-change-lost-password-page-if-on-certain-url.php
<?php
/* shortcode that will output the Logout URL with Kiosk URL redirect, as anchor and text */
// [fs_kiosk_logout_url_anchor class="whatever-it-is you-want"]Log Out[/fs_kiosk_logout_url_anchor]
add_shortcode( 'fs_kiosk_logout_url_anchor', 'fs_sc_kiosk_logout_url_anchor' );
function fs_sc_kiosk_logout_url_anchor( $atts, $content = null ) {
// define attributes and their defaults
$a = shortcode_atts( array(
'class' => 'kiosk-logout-url-anchor'
), $atts );
@Garconis
Garconis / progress-maps-trigger-search-form-and-wrap-links.js
Last active Dec 7, 2018
Progress Maps | Trigger the search form box if a button is clicked, and also wrap URLs with a link
View progress-maps-trigger-search-form-and-wrap-links.js
@Garconis
Garconis / wpdatatables-content-manipulation.js
Created Oct 23, 2018
WordPress | wpDataTables column data overrides
View wpdatatables-content-manipulation.js
// Code for inventory image
function inventoryTable(){
// grab the URL in the new column and make into an image
jQuery('td.inventory-col-photo a').each(function () {
var image_anchor = jQuery(this).find("a");
var image_url = jQuery(this).attr("href");
//jQuery(this).prepend(jQuery('<img>',{class:'theImg',src:'theImg.png'}))
jQuery(this).html('<img src="' + image_url + '">');
});
// grab text in the Stock # column and assume its OK to make into a clickable image with that filename
View woocommerce-products-per-page-plugin-with-divi.php
<?php
// help make the plugin of WooCommerce Products Per Page work with the Divi Theme
add_action( 'pre_get_posts', 'fs_custom_posts_per_page', 30 );
function fs_custom_posts_per_page( $query = false ) {
if ( is_admin() ) return;
if ( ! is_a( $query, 'WP_Query' ) || ! $query->is_main_query() ) return;
if ( $query->is_category ) {
$query->set( 'posts_per_page', apply_filters( 'loop_shop_per_page', 9 ) );
@Garconis
Garconis / divi-show-section-based-on-clicked-link-id.js
Last active Mar 4, 2019
Divi | Show a section that has an ID when the link with that ID is clicked (and hide the others) — good for creating faux tabs and tab content
View divi-show-section-based-on-clicked-link-id.js
@Garconis
Garconis / highlight-link-if-section-in-viewport.js
Last active Mar 4, 2019
WordPress | Highlight Nav Menu Item if ID is in Viewport
View highlight-link-if-section-in-viewport.js
@Garconis
Garconis / exclude-cpt-from-search.php
Created Sep 20, 2018
WordPress | Exclude certain Custom Post Types from search
View exclude-cpt-from-search.php
<?php
// include only certain post types in the search results
function gc_filter_search($query) {
if (!$query->is_admin && $query->is_search) {
$query->set('post_type', array('post', 'page', 'book'));
}
return $query;
}
add_filter('pre_get_posts', 'gc_filter_search');
@Garconis
Garconis / acf-post-loop-based-on-meta-and-taxonomy.php
Created Sep 5, 2018
WordPress | Loop for displaying only certain posts with certain ACF content and taxonomy
View acf-post-loop-based-on-meta-and-taxonomy.php
<?php
// create shortcode to list all addresses of a "Location" Page Type
add_shortcode( 'fs-location-address-loop', 'fs_sc_location_address_loop' );
function fs_sc_location_address_loop( $atts ) {
ob_start();
// define attributes and their defaults
extract( shortcode_atts( array (
'post_type' => 'page',
You can’t perform that action at this time.