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 / 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
*/
<?php
global $product;
echo 'The current product ID is: '.$product->get_id();
php_value memory_limit 256M
<?php
// Update a post programmatically
$my_post_id = 15
$update_post = array(
'ID' => $my_post_id,
'post_title' => 'My new post title',
'post_content' => 'Overwrite post content',
'post_status' => 'public'
);
@someguy9
someguy9 / wordpress-insert-custom-post.php
Last active February 14, 2023 17:46
Insert a custom post type programmatically in WordPress https://smartwp.com/wordpress-insert-post-programmatically/
<?php
// Insert custom post programmatically
$new_post = array(
'post_title' => 'My new example post',
'post_content' => 'My new content!',
'post_status' => 'public',
'post_type' => 'my_post_type'
);
$post_id = wp_insert_post( $new_post );
<?php
// Insert post programmatically
$new_post = array(
'post_title' => 'My new post',
'post_content' => 'Content to insert.',
'post_status' => 'publish'
);
$post_id = wp_insert_post( $new_post );
<?php
// Overwrite MightyShare title font-weight
function mightyshare_set_font_weight( $template_options ) {
$template_options['title_fontWeight'] = '900';
return $template_options;
}
add_filter( 'mightyshare_filter_post', 'mightyshare_set_font_weight', 10, 3 );
<?php
// Overwrite MightyShare fallback image
function mightyshare_overwrite_fallback_image( $template_options ) {
var_dump(get_post_meta( $template_options['ID'], 'mightyshare_enabled', true ));
if ( get_post_thumbnail_id($template_options['ID']) !== $template_options['background'] && empty( get_post_meta( $template_options['ID'], 'mightyshare_background', true ) ) ) {
$template_options['background'] = 'https://images.unsplash.com/photo-1674757273875-e47dbfbda82c?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2831&q=80';
}
return $template_options;
}