create_folder_and_upload_file

function create_custom_directory($dir_name) { $upload_dir = wp_upload_dir(); // Get the uploads directory array $custom_dir = $upload_dir[‘basedir’] . ‘/’ . $dir_name; // Specify the custom folder if (!file_exists($custom_dir)) { wp_mkdir_p($custom_dir); if(file_exists($custom_dir)) { return “Directory created successfully.”; } else { return “Failed to…Continue reading

Change POSTS to NEWS in WP dashboard

// Change POSTS to News in WP dashboard add_action( ‘admin_menu’, ‘rd_change_post_menu_label’ ); add_action( ‘init’, ‘rd_change_post_object_label’ ); function rd_change_post_menu_label() { global $menu; global $submenu; $menu[5][0] = ‘News’; $submenu[‘edit.php’][5][0] = ‘News’; $submenu[‘edit.php’][10][0] = ‘Add News’; $submenu[‘edit.php’][16][0] = ‘News Tags’; echo ”; }…Continue reading

custom_realtime_find_replace

function custom_realtime_find_replace($content) { // Define your replacement rules $rules = [ // Example “SOME_KEY_001” => “SOME_VALUE”, “SOME_KEY_002” => “SOME_VALUE2”, ]; // Loop through the rules and replace content foreach ($rules as $find => $replace) { $content = str_replace($find, $replace, $content);…Continue reading

performance

add_action(‘init’, function () { remove_action(‘wp_head’, ‘wp_resource_hints’, 2, 99); }); /** * Disable emojis */ add_action(‘init’, function () { 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’); remove_filter(‘wp_mail’, ‘wp_staticize_emoji_for_email’); add_filter(‘tiny_mce_plugins’, function ($plugins) { if (is_array($plugins)) {…Continue reading

add_custom_javascript_review_sites

function add_custom_javascript() { // Check if we’re on a single post or page if(is_singular()) { // Get the post ID of the current post or page $post_id = get_the_ID(); // Check if the custom field ‘funnel’ exists and get its…Continue reading

disable_content_title_for_all_posts

function disable_content_title_for_all_posts() { $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1, ‘fields’ => ‘ids’, // Only get post IDs to improve performance ); $posts = get_posts($args); foreach ($posts as $post_id) { // Assuming ‘_disable_title’ is the meta key and…Continue reading

Remove users from WP-JSON

add_filter(‘rest_endpoints’, function( $endpoints ) { if ( isset( $endpoints[‘/wp/v2/users’] ) ) { unset( $endpoints[‘/wp/v2/users’] ); } if ( isset( $endpoints[‘/wp/v2/users/(?P[\d]+)’] ) ) { unset( $endpoints[‘/wp/v2/users/(?P[\d]+)’] ); } return $endpoints; });Continue reading

Add the page slug body class

function wpcode_snippet_add_slug_body_class( $classes ) { global $post; if ( isset( $post ) ) { $classes[] = $post->post_type . ‘-‘ . $post->post_name; } return $classes; } add_filter( ‘body_class’, ‘wpcode_snippet_add_slug_body_class’ );Continue reading

webhooks

add_filter( ‘wpforms_webhooks_process_fill_http_body_params_value’, function ( $filled_params, $params, $process ) { foreach ( $filled_params as $key => $param ) { if ( $key == “booking_date” ) { $filled_params[ $key ] = $param[‘value’]; } elseif ( $key == “start_time” ) { $filled_params[ $key…Continue reading