Skip to content

Instantly share code, notes, and snippets.

View MrJoshFisher's full-sized avatar

Josh Fisher MrJoshFisher

View GitHub Profile
@MrJoshFisher
MrJoshFisher / .htaccess
Created December 24, 2021 10:47
[.htaccess redirects]
1. Redirect All Web Traffic
If you have existing code in your .htaccess, add the following:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
2. Redirect Only a Specific Domain
For redirecting a specific domain to use HTTPS, add the following:
RewriteEngine On
@MrJoshFisher
MrJoshFisher / script.js
Created November 18, 2021 13:11
[Event Tracking]
// mailto function
$('a[href^="mailto:"]').click(function(){
var emaillink=jQuery(this).attr('href');
gtag('event', 'contact', { 'event_category' : 'Email Enquiry', 'event_action' : 'Mailto Click', 'event_label' : emaillink});
return true;
});
// tel: function
$('a[href^="tel:"]').click(function(){
@MrJoshFisher
MrJoshFisher / functions.php
Created October 20, 2021 09:45
[Enqueue CSS / JS] #wordpress
function add_theme_scripts() {
wp_enqueue_style( 'style', get_stylesheet_uri() );
wp_enqueue_style( 'slider', get_template_directory_uri() . '/css/slider.css', array(), '1.1', 'all');
wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js', array ( 'jquery' ), 1.1, true);
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
@MrJoshFisher
MrJoshFisher / functions.php
Created October 7, 2021 09:23
[custom admin column]
add_filter('manage_<POSTTYPE>_posts_columns', function ($columns) {
return array_merge($columns, ['verified' => __('Verified', 'textdomain')]);
});
add_action('manage_<POSTTYPE>_posts_custom_column', function ($column_key, $post_id) {
if ($column_key == 'verified') {
$verified = get_post_meta($post_id, 'verified', true);
if ($verified) {
echo '<span style="color:green;">';
_e('Yes', 'textdomain');
@MrJoshFisher
MrJoshFisher / steam_game_list_09_2021.csv
Created September 27, 2021 22:41
Every Game ON Steam 09/2021
We can't make this file beautiful and searchable because it's too large.
Title,Link,Price
4:00 PM,https://store.steampowered.com/app/281840/4PM/?snr=1_7_7_230_150_447,£1.99
3.04,https://store.steampowered.com/app/952950/0304/?snr=1_7_7_230_150_223,£3.99
5,https://store.steampowered.com/app/1132070/50/?snr=1_7_7_230_150_161,£0.79£0.39
6,https://store.steampowered.com/app/1165860/60/?snr=1_7_7_230_150_159,£0.79£0.39
16,https://store.steampowered.com/bundle/20256/16/?snr=1_7_7_230_150_308,£3.20
21,https://store.steampowered.com/app/938520/21/?snr=1_7_7_230_150_564,£3.99£0.39
50.05,https://store.steampowered.com/app/688810/5005/?snr=1_7_7_230_150_781,Free
50.05,https://store.steampowered.com/app/688810/5005/?snr=1_7_7_230_150_837,Free
64,https://store.steampowered.com/app/578850/640/?snr=1_7_7_230_150_76,£1.99
@MrJoshFisher
MrJoshFisher / functions.php
Created September 16, 2021 09:41
[Add Woocommerce Tab] #wordpress
/**
* Add a custom product data tab
*/
add_filter('woocommerce_product_tabs', 'woo_new_product_tab');
function woo_new_product_tab($tabs)
{
// Adds the new tab
$tabs['test_tab'] = array(
@MrJoshFisher
MrJoshFisher / functions.php
Created September 14, 2021 08:40
[Add Taxonomy Filter To Custom Post Type] #wordpress #php
add_action('restrict_manage_posts', 'tsm_filter_post_type_by_taxonomy');
function tsm_filter_post_type_by_taxonomy() {
global $typenow;
$post_type = 'property'; // change to your post type
$taxonomy = 'section'; // change to your taxonomy
if ($typenow == $post_type) {
$selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
$info_taxonomy = get_taxonomy($taxonomy);
wp_dropdown_categories(array(
@MrJoshFisher
MrJoshFisher / functions.php
Last active June 17, 2022 11:05
[Register Menu In WordPress] #wordpress
function wpb_custom_new_menu() {
register_nav_menus(
array(
'my-custom-menu' => __( 'My Custom Menu' ),
'extra-menu' => __( 'Extra Menu' )
)
);
}
add_action( 'init', 'wpb_custom_new_menu' );
@MrJoshFisher
MrJoshFisher / functions.php
Created August 20, 2021 13:18
[Register Sidebar] How to register sidebars in wordpress #wordpress
<?php
function wpb_widgets_init() {
register_sidebar( array(
'name' => __( 'Main Sidebar', 'wpb' ),
'id' => 'sidebar-1',
'description' => __( 'The main sidebar appears on the right on each page except the front page template', 'wpb' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
@MrJoshFisher
MrJoshFisher / functions.php
Created August 12, 2021 14:38
[Remove product-category from ULR] #wordpress
1.
add_filter('request', function( $vars ) {
global $wpdb;
if( ! empty( $vars['pagename'] ) || ! empty( $vars['category_name'] ) || ! empty( $vars['name'] ) || ! empty( $vars['attachment'] ) ) {
$slug = ! empty( $vars['pagename'] ) ? $vars['pagename'] : ( ! empty( $vars['name'] ) ? $vars['name'] : ( !empty( $vars['category_name'] ) ? $vars['category_name'] : $vars['attachment'] ) );
$exists = $wpdb->get_var( $wpdb->prepare( "SELECT t.term_id FROM $wpdb->terms t LEFT JOIN $wpdb->term_taxonomy tt ON tt.term_id = t.term_id WHERE tt.taxonomy = 'product_cat' AND t.slug = %s" ,array( $slug )));
if( $exists ){
$old_vars = $vars;
$vars = array('product_cat' => $slug );
if ( !empty( $old_vars['paged'] ) || !empty( $old_vars['page'] ) )