Skip to content

Instantly share code, notes, and snippets.

View someguy9's full-sized avatar
🏠
Working from home

Andy Feliciotti someguy9

🏠
Working from home
View GitHub Profile
@someguy9
someguy9 / limit-comment-length.php
Created April 18, 2024 14:09
Limit comment length in WordPress
<?php
// Limit the comment length to 6000 characters and a minimum of 50 characters in WordPress
add_filter( 'preprocess_comment', 'smartwp_limit_comment_length' );
function smartwp_limit_comment_length( $comment ) {
// Limit the comments to 6000 characters
if ( strlen( $comment['comment_content'] ) > 6000 ) {
wp_die('Comment is too long. Comments must be under 6000 characters.');
}
@someguy9
someguy9 / featured-image-wordpress-rss-feed.php
Last active March 6, 2024 17:23
Display Featured Image in WordPress RSS Feed
@someguy9
someguy9 / disable-emojis-wordpress.php
Last active December 21, 2023 13:45
Disable emojis in WordPress
<?php
//Disable emojis in WordPress
add_action( 'init', 'smartwp_disable_emojis' );
function smartwp_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_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
@someguy9
someguy9 / wp-remove-gutenberg-block-library-css.php
Last active November 21, 2023 08:00
Removed the "/wp-includes/css/dist/block-library/style.min.css" file from your WordPress site
<?php
//Remove Gutenberg Block Library CSS from loading on the frontend
function smartwp_remove_wp_block_library_css(){
wp_dequeue_style( 'wp-block-library' );
wp_dequeue_style( 'wp-block-library-theme' );
wp_dequeue_style( 'wc-blocks-style' ); // Remove WooCommerce block CSS
}
add_action( 'wp_enqueue_scripts', 'smartwp_remove_wp_block_library_css', 100 );
@someguy9
someguy9 / style.css
Created November 19, 2023 20:42
Child theme style.css example in WordPress https://smartwp.com/child-theme/
/*
Theme Name: Twenty Fifteen Child
Description: Twenty Fifteen Child Theme
Author: John Doe
Author URI: http://example.com
Template: twentyfifteen
Version: 1.0.0
Text Domain: twentyfifteenchild
*/
@someguy9
someguy9 / disable-wordpress-admin-new-user-notification.php
Created May 14, 2020 19:05
Disable the WordPress new user email notification sent to the site admin
<?php
//Disable the new user notification sent to the site admin
function smartwp_disable_new_user_notifications() {
//Remove original use created emails
remove_action( 'register_new_user', 'wp_send_new_user_notifications' );
remove_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10, 2 );
//Add new function to take over email creation
add_action( 'register_new_user', 'smartwp_send_new_user_notifications' );
add_action( 'edit_user_created_user', 'smartwp_send_new_user_notifications', 10, 2 );
<?php
global $product;
echo 'The current product ID is: '.$product->get_id();
@someguy9
someguy9 / shortcode-exists.php
Last active July 18, 2023 15:22
Check if a shortcode already exists in WordPress https://smartwp.com/check-if-shortcode-exists/
<?php
if ( shortcode_exists( 'image_gallery' ) ) {
echo 'The [image_gallery] shortcode already exists';
}
if ( !shortcode_exists( 'image_gallery' ) ) {
echo 'The [image_gallery] shortcode does not exist';
}
@someguy9
someguy9 / add-admin-user-wordpress.php
Created March 17, 2020 12:35
Create an admin user in 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 );
php_value memory_limit 256M