Skip to content

Instantly share code, notes, and snippets.

View MrJoshFisher's full-sized avatar

Josh Fisher MrJoshFisher

View GitHub Profile
@MrJoshFisher
MrJoshFisher / functions.php
Created December 13, 2020 00:07
[Add an Admin User with PHP] #WordPress
<?php
//Create an admin user
function smartwp_create_admin_user(){
$username = 'yourusername';
$password = '2JyAEQJ9B9Jf5T8a';
$email = 'change@me.com';
//This will ensure it only tries to create the user once (based on email/username)
if ( !username_exists( $username ) && !email_exists( $email ) ) {
$userid = wp_create_user( $username, $password, $email );
$user = new WP_User( $userid );
@MrJoshFisher
MrJoshFisher / functions.php
Created February 3, 2021 09:43
[Popular Posts]
function wpb_set_post_views($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
}else{
$count++;
update_post_meta($postID, $count_key, $count);
@MrJoshFisher
MrJoshFisher / functions.php
Created March 15, 2021 15:31
[Disable Emojis]
/**
* Disable the emoji's
*/
function disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
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">',
'after_title' => '</h3>',
@MrJoshFisher
MrJoshFisher / scripts.js
Created May 17, 2021 09:46
[get URL parameter using jQuery or plain JavaScript]
/* https://stackoverflow.com/questions/19491336/how-to-get-url-parameter-using-jquery-or-plain-javascript */
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
@MrJoshFisher
MrJoshFisher / .htaccess
Created May 17, 2021 15:02
[Add .html to URLS]
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{3,4}
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1.html
@MrJoshFisher
MrJoshFisher / functions.php
Created May 25, 2021 14:04
[Get Featured Image]
$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true);
$thumb_url = $thumb_url_array[0];
@MrJoshFisher
MrJoshFisher / functions.php
Created July 5, 2021 16:30
[Chnage return to shop url] #wordpress
function store_mall_wc_empty_cart_redirect_url() {
$url = 'http://example.com/sample-page'; // change this link to your need
return esc_url( $url );
}
add_filter( 'woocommerce_return_to_shop_redirect', 'store_mall_wc_empty_cart_redirect_url' );
@MrJoshFisher
MrJoshFisher / product-template.liquid
Created July 20, 2021 15:16
[Radio Buttons Shopify Product] #shopify #liquid
{% for option in product.options_with_values %}
<label {% if option.name == 'default' %}class="label--hidden" {% endif %}for="SingleOptionSelector-{{ forloop.index0 }}">
{{ option.name }}
</label>
{% assign option_position = forloop.index %}
<fieldset class="product-options-fieldset">
{%- for value in option.values -%}
<input type="radio" class="single-option-selector-{{ section.id }} "
{% if option.selected_value == value %} checked="checked"{% endif %}
value="{{ value | escape }}"
@MrJoshFisher
MrJoshFisher / bashscript.txt
Created July 22, 2021 17:57
[Linux - Compress, SFTP Remove Folder] #linux
// ADD SSH KEY OF SERVER TO STORAGE DEVICE
tar -zcvf DIRECTORYNAME.tar.gz DIRECTORY
sftp USER@SERVER:/SIRECTORY <<< $'put -r DIRECTORYNAME.tar.gz'
rm -f DIRECTORYNAME.com.tar.gz