Skip to content

Instantly share code, notes, and snippets.

Avatar

ErnestPH

View GitHub Profile
@ErnestPH
ErnestPH / exclude_scripts
Last active Aug 7, 2020
Exclude Scripts (Google tags, FB Pixel) on all blog posts and the blog page on a specific Multisite. Filter is added on Head, Footer and Body tag.
View exclude_scripts
function excluding_blogs_header() {
// exclude from Posts Page (blog) page and all blog posts on the Main site (multisite)
if( !is_single() && !is_home() && 1 === get_current_blog_id() ) {
$code = "<script> Your script here </script>";
} else {
  $code = null;
}
  echo $code;
}
@ErnestPH
ErnestPH / gist:d0627b1e81e2929e95314d09be9425b5
Created Feb 26, 2020
Redirect users to a different URL(default is My Account) after WooCommerce login.
View gist:d0627b1e81e2929e95314d09be9425b5
// After login, users (customers and subscribers only) are redirected to the "Video Library" page -> get_permalink( $post = 6913 );
function wc_custom_user_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user
$role = $user->roles[0];
$dashboard = admin_url();
// video library URL
$videolibrary = get_permalink( $post = 6913 );
@ErnestPH
ErnestPH / gist:9798a923f98dc35e29a30a7dc49561fb
Created Feb 26, 2020
Add a Class or ID in Wordpress specific menu <a> tag instead of the <li> tag using jQuery
View gist:9798a923f98dc35e29a30a7dc49561fb
// class name example
jQuery( "#menu-item-30142 a" ).ready( function( $ ){
$( "#menu-item-30142 a" ).addClass("class-name");
});
// #menu-item-30142 a is the element id with <a> tag
@ErnestPH
ErnestPH / gist:6318b93f95aba42f33f9c76891f01045
Created Feb 26, 2020
Adding DEFER or ASYNC in JS scripts via functions.php
View gist:6318b93f95aba42f33f9c76891f01045
// Single script
function make_script_defer( $tag, $handle, $src ){
if ( 'wp_register_script-name-1' != $handle ) {
return $tag;
}
return str_replace( '<script', '<script defer', $tag );
}
add_filter( 'script_loader_tag', 'make_script_defer', 10, 3 );
@ErnestPH
ErnestPH / gist:dc72a2cd0dfe6220e2ac411791574e69
Created Feb 26, 2020
Modify texts in WooCommerce Subscription plugin
View gist:dc72a2cd0dfe6220e2ac411791574e69
// change the “for” to "up to for"
function change_subscription_product_string( $subscription_string, $product, $include ) {
if( $include ){
$subscription_string = str_replace('for', 'for up to', $subscription_string);
}
return $subscription_string;
}
add_filter( 'woocommerce_subscriptions_product_price_string', 'change_subscription_product_string', 10, 3 );
@ErnestPH
ErnestPH / .scpt
Created Jun 12, 2019
Apple script for emailing multiple accounts in Mac Mail
View .scpt
set {firstName, eAddress} to getData()
repeat with i from 1 to count firstName
tell application "Mail"
activate
set mymail to make new outgoing message at the beginning of outgoing messages with properties {subject:"Great new! We are now offering Radio Mobile Apps for Android and iOS here at Internet Radio Cast on VPS"}
tell mymail
make new to recipient at beginning of to recipients with properties {address:item i of eAddress}
delay 5
set content to "Hi " & item i of firstName & "
@ErnestPH
ErnestPH / Custom WooCommerce login
Last active Aug 9, 2019
Custom WooCommerce login and dashboard button
View Custom WooCommerce login
add_filter( 'wp_nav_menu_items', 'custom_login_dashboard', 10, 2 );
function custom_login_dashboard( $items, $args ) {
if (is_user_logged_in() && $args->primary-menu == 'primary') { //change your theme registered menu name to suit - currently for DIVI theme
$items .= '<li><a class="mydashboard" href="'. get_permalink( wc_get_page_id( 'myaccount' ) ) .'">My Dashboard</a></li>' . '<style> #top-header { background: #7a0101!important;} #main-header, #main-footer, #footer-bottom { background: black!important;}</style>';
//the style is changing the theme's color once you are logged in
}
elseif (!is_user_logged_in() && $args->primary-menu == 'primary') {//change your theme registered menu name to suit
$items .= '<li><a class="mydashboard" href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">Log In</a></li>';
}
You can’t perform that action at this time.