D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
realadss
/
www
/
wp-content
/
uploads
/
wpcode
/
cache
/
library
/
Filename :
snippets.json
back
Copy
{"categories":[{"name":"Most Popular","slug":"most-popular"},{"name":"Admin","slug":"admin"},{"name":"Archive","slug":"archive"},{"name":"Attachments","slug":"attachments"},{"name":"Comments","slug":"comments"},{"name":"Disable","slug":"disable"},{"name":"Login","slug":"login"},{"name":"RSS Feeds","slug":"rss-feeds"},{"name":"Widgets","slug":"widgets"}],"snippets":[{"library_id":63,"title":"Add an Edit Post Link to Archives","code":"edit_post_link( __( '{Edit}' ) );\r\n","note":"Make it easier to edit posts when viewing archives. Or on single pages. If you...","categories":["archive"],"code_type":"php","needs_auth":false},{"library_id":947,"title":"Add default ALT to avatar\/Gravatar Images","code":"add_filter(\r\n\t'pre_get_avatar_data',\r\n\tfunction ( $atts ) {\r\n\t\tif ( empty( $atts['alt'] ) ) {\r\n\t\t\tif ( have_comments() ) {\r\n\t\t\t\t$author = get_comment_author();\r\n\t\t\t} else {\r\n\t\t\t\t$author = get_the_author_meta( 'display_name' );\r\n\t\t\t}\r\n\t\t\t$alt = sprintf( 'Avatar for %s', $author );\r\n\r\n\t\t\t$atts['alt'] = $alt;\r\n\t\t}\r\n\t\treturn $atts;\r\n\t}\r\n);","note":"Add the user's name as a default alt tag to the Gravatar images loaded on...","categories":["attachments"],"code_type":"php","needs_auth":false},{"library_id":6562,"title":"Add Featured Image Column","code":"add_filter( 'manage_posts_columns', function ( $columns ) {\r\n\t\/\/ You can change this to any other position by changing 'title' to the name of the column you want to put it after.\r\n\t$move_after = 'title';\r\n\t$move_after_key = array_search( $move_after, array_keys( $columns ), true );\r\n\r\n\t$first_columns = array_slice( $columns, 0, $move_after_key + 1 );\r\n\t$last_columns = array_slice( $columns, $move_after_key + 1 );\r\n\r\n\treturn array_merge(\r\n\t\t$first_columns,\r\n\t\tarray(\r\n\t\t\t'featured_image' => __( 'Featured Image' ),\r\n\t\t),\r\n\t\t$last_columns\r\n\t);\r\n} );\r\n\r\nadd_action( 'manage_posts_custom_column', function ( $column ) {\r\n\tif ( 'featured_image' === $column ) {\r\n\t\tthe_post_thumbnail( array( 300, 80 ) );\r\n\t}\r\n} );","note":"Display the featured image in the list of posts in the admin.","categories":["admin","attachments"],"code_type":"php","needs_auth":false},{"library_id":44,"title":"Add Featured Images to RSS Feeds","code":"\/**\r\n * Add the post thumbnail, if available, before the content in feeds.\r\n *\r\n * @param string $content The post content.\r\n *\r\n * @return string\r\n *\/\r\nfunction wpcode_snippet_rss_post_thumbnail( $content ) {\r\n\tglobal $post;\r\n\tif ( has_post_thumbnail( $post->ID ) ) {\r\n\t\t$content = '<p>' . get_the_post_thumbnail( $post->ID ) . '<\/p>' . $content;\r\n\t}\r\n\r\n\treturn $content;\r\n}\r\n\r\nadd_filter( 'the_excerpt_rss', 'wpcode_snippet_rss_post_thumbnail' );\r\nadd_filter( 'the_content_feed', 'wpcode_snippet_rss_post_thumbnail' );","note":"Extend your site's RSS feeds by including featured images in the feed.","categories":["rss-feeds"],"code_type":"php","needs_auth":false},{"library_id":13021,"title":"Add Media File Size Column","code":"add_filter( 'manage_upload_columns', function ( $columns ) {\r\n\t$columns ['file_size'] = esc_html__( 'File size' );\r\n\r\n\treturn $columns;\r\n} );\r\n\r\nadd_action( 'manage_media_custom_column', function ( $column_name, $media_item ) {\r\n\tif ( 'file_size' !== $column_name || ! wp_attachment_is_image( $media_item ) ) {\r\n\t\treturn;\r\n\t}\r\n\t$filesize = size_format( filesize( get_attached_file( $media_item ) ), 2 );\r\n\techo esc_html( $filesize );\r\n\r\n}, 10, 2 );\r\n","note":"Display the file size in a separate column in the Media screen","categories":["attachments"],"code_type":"php","needs_auth":false},{"library_id":65,"title":"Add the Page Slug to Body Class","code":"function wpcode_snippet_add_slug_body_class( $classes ) {\r\n\tglobal $post;\r\n\tif ( isset( $post ) ) {\r\n\t\t$classes[] = $post->post_type . '-' . $post->post_name;\r\n\t}\r\n\r\n\treturn $classes;\r\n}\r\n\r\nadd_filter( 'body_class', 'wpcode_snippet_add_slug_body_class' );","note":"Add the page slug to the body class for better styling.","categories":["archive"],"code_type":"php","needs_auth":false},{"library_id":54,"title":"Allow SVG Files Upload","code":"\/**\r\n * Allow SVG uploads for administrator users.\r\n *\r\n * @param array $upload_mimes Allowed mime types.\r\n *\r\n * @return mixed\r\n *\/\r\nadd_filter(\r\n\t'upload_mimes',\r\n\tfunction ( $upload_mimes ) {\r\n\t\t\/\/ By default, only administrator users are allowed to add SVGs.\r\n\t\t\/\/ To enable more user types edit or comment the lines below but beware of\r\n\t\t\/\/ the security risks if you allow any user to upload SVG files.\r\n\t\tif ( ! current_user_can( 'administrator' ) ) {\r\n\t\t\treturn $upload_mimes;\r\n\t\t}\r\n\r\n\t\t$upload_mimes['svg'] = 'image\/svg+xml';\r\n\t\t$upload_mimes['svgz'] = 'image\/svg+xml';\r\n\r\n\t\treturn $upload_mimes;\r\n\t}\r\n);\r\n\r\n\/**\r\n * Add SVG files mime check.\r\n *\r\n * @param array $wp_check_filetype_and_ext Values for the extension, mime type, and corrected filename.\r\n * @param string $file Full path to the file.\r\n * @param string $filename The name of the file (may differ from $file due to $file being in a tmp directory).\r\n * @param string[] $mimes Array of mime types keyed by their file extension regex.\r\n * @param string|false $real_mime The actual mime type or false if the type cannot be determined.\r\n *\/\r\nadd_filter(\r\n\t'wp_check_filetype_and_ext',\r\n\tfunction ( $wp_check_filetype_and_ext, $file, $filename, $mimes, $real_mime ) {\r\n\r\n\t\tif ( ! $wp_check_filetype_and_ext['type'] ) {\r\n\r\n\t\t\t$check_filetype = wp_check_filetype( $filename, $mimes );\r\n\t\t\t$ext = $check_filetype['ext'];\r\n\t\t\t$type = $check_filetype['type'];\r\n\t\t\t$proper_filename = $filename;\r\n\r\n\t\t\tif ( $type && 0 === strpos( $type, 'image\/' ) && 'svg' !== $ext ) {\r\n\t\t\t\t$ext = false;\r\n\t\t\t\t$type = false;\r\n\t\t\t}\r\n\r\n\t\t\t$wp_check_filetype_and_ext = compact( 'ext', 'type', 'proper_filename' );\r\n\t\t}\r\n\r\n\t\treturn $wp_check_filetype_and_ext;\r\n\r\n\t},\r\n\t10,\r\n\t5\r\n);\r\n","note":"Add support for SVG files to be uploaded in WordPress media.","categories":["most-popular","attachments"],"code_type":"php","needs_auth":false},{"library_id":56,"title":"Automatically Link Featured Images to Posts","code":"\/**\r\n * Wrap the thumbnail in a link to the post.\r\n * Only use this if your theme doesn't already wrap thumbnails in a link.\r\n *\r\n * @param string $html The thumbnail HTML to wrap in an anchor.\r\n * @param int $post_id The post ID.\r\n * @param int $post_image_id The image id.\r\n *\r\n * @return string\r\n *\/\r\nfunction wpcode_snippet_autolink_featured_images( $html, $post_id, $post_image_id ) {\r\n\t$html = '<a href=\"' . get_permalink( $post_id ) . '\" title=\"' . esc_attr( get_the_title( $post_id ) ) . '\">' . $html . '<\/a>';\r\n\r\n\treturn $html;\r\n}\r\n\r\nadd_filter( 'post_thumbnail_html', 'wpcode_snippet_autolink_featured_images', 20, 3 );\r\n","note":"Wrap featured images in your theme in links to posts.","categories":["attachments"],"code_type":"php","needs_auth":false},{"library_id":64,"title":"Change \"Howdy Admin\" in Admin Bar","code":"function wpcode_snippet_replace_howdy( $wp_admin_bar ) {\r\n\r\n\t\/\/ Edit the line below to set what you want the admin bar to display intead of \"Howdy,\".\r\n\t$new_howdy = 'Welcome,';\r\n\r\n\t$my_account = $wp_admin_bar->get_node( 'my-account' );\r\n\t$wp_admin_bar->add_node(\r\n\t\tarray(\r\n\t\t\t'id' => 'my-account',\r\n\t\t\t'title' => str_replace( 'Howdy,', $new_howdy, $my_account->title ),\r\n\t\t)\r\n\t);\r\n}\r\n\r\nadd_filter( 'admin_bar_menu', 'wpcode_snippet_replace_howdy', 25 );\r\n","note":"Customize the \"Howdy\" message in the admin bar.","categories":["admin"],"code_type":"php","needs_auth":false},{"library_id":43,"title":"Change Admin Panel Footer Text","code":"add_filter(\r\n\t'admin_footer_text',\r\n\tfunction ( $footer_text ) {\r\n\t\t\/\/ Edit the line below to customize the footer text.\r\n\t\t$footer_text = 'Powered by <a href=\"https:\/\/www.wordpress.org\" target=\"_blank\" rel=\"noopener\">WordPress<\/a> | WordPress Tutorials: <a href=\"https:\/\/www.wpbeginner.com\" target=\"_blank\" rel=\"noopener\">WPBeginner<\/a>';\r\n\t\t\r\n\t\treturn $footer_text;\r\n\t}\r\n);","note":"Display custom text in the admin panel footer with this snippet.","categories":["admin"],"code_type":"php","needs_auth":false},{"library_id":50,"title":"Change Excerpt Length","code":"add_filter(\r\n\t'excerpt_length',\r\n\tfunction ( $length ) {\r\n\t\t\/\/ Number of words to display in the excerpt.\r\n\t\treturn 40;\r\n\t},\r\n\t500\r\n);","note":"Update the length of the Excerpts on your website using this snippet.","categories":["archive"],"code_type":"php","needs_auth":false},{"library_id":964,"title":"Change Outgoing Email Sender","code":"\/\/ Please edit the address and name below before activating this snippet.\r\n\/\/ Change the From address.\r\nadd_filter( 'wp_mail_from', function ( $original_email_address ) {\r\n\treturn 'tim.smith@example.com';\r\n} );\r\n\r\n\/\/ Change the From name.\r\nadd_filter( 'wp_mail_from_name', function ( $original_email_from ) {\r\n\treturn 'Tim Smith';\r\n} );","note":"Change the outgoing sender name and email address. Don't forget to edit the snippet with...","categories":["admin"],"code_type":"php","needs_auth":false},{"library_id":49,"title":"Change Read More Text for Excerpts","code":"function wpcode_snippets_change_read_more( $read_more, $read_more_text ) {\r\n\r\n\t\/\/ Edit the line below to add your own \"Read More\" text.\r\n\t$custom_text = 'Read the whole post';\r\n\r\n\t$read_more = str_replace( $read_more_text, $custom_text, $read_more );\r\n\r\n\treturn $read_more;\r\n}\r\n\r\nadd_filter( 'the_content_more_link', 'wpcode_snippets_change_read_more', 15, 2 );\r\n","note":"Customize the \"Read More\" text that shows up after excerpts.","categories":["archive"],"code_type":"php","needs_auth":false},{"library_id":12,"title":"Completely Disable Comments","code":"add_action('admin_init', function () {\r\n \/\/ Redirect any user trying to access comments page\r\n global $pagenow;\r\n \r\n if ($pagenow === 'edit-comments.php') {\r\n wp_safe_redirect(admin_url());\r\n exit;\r\n }\r\n\r\n \/\/ Remove comments metabox from dashboard\r\n remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');\r\n\r\n \/\/ Disable support for comments and trackbacks in post types\r\n foreach (get_post_types() as $post_type) {\r\n if (post_type_supports($post_type, 'comments')) {\r\n remove_post_type_support($post_type, 'comments');\r\n remove_post_type_support($post_type, 'trackbacks');\r\n }\r\n }\r\n});\r\n\r\n\/\/ Close comments on the front-end\r\nadd_filter('comments_open', '__return_false', 20, 2);\r\nadd_filter('pings_open', '__return_false', 20, 2);\r\n\r\n\/\/ Hide existing comments\r\nadd_filter('comments_array', '__return_empty_array', 10, 2);\r\n\r\n\/\/ Remove comments page in menu\r\nadd_action('admin_menu', function () {\r\n remove_menu_page('edit-comments.php');\r\n});\r\n\r\n\/\/ Remove comments links from admin bar\r\nadd_action('admin_bar_menu', function () {\r\n remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);\r\n}, 0);","note":"Disable comments for all post types, in the admin and the frontend.","categories":["most-popular","comments"],"code_type":"php","needs_auth":false},{"library_id":6572,"title":"Decrease Auto-Save Interval","code":"if ( ! defined( 'AUTOSAVE_INTERVAL' ) ) {\r\n\t\/\/ Change 5 to the number of minutes you want to use.\r\n\tdefine( 'AUTOSAVE_INTERVAL', 5 * MINUTE_IN_SECONDS );\r\n}","note":"Change post editor auto-save to 5 minutes instead of 1.","categories":["admin"],"code_type":"php","needs_auth":false},{"library_id":48,"title":"Delay Posts in RSS Feeds","code":"function wpcode_snippet_publish_later_on_feed( $where ) {\r\n\r\n\tglobal $wpdb;\r\n\r\n\tif ( is_feed() ) {\r\n\t\t\/\/ Timestamp in WP-format.\r\n\t\t$now = gmdate( 'Y-m-d H:i:s' );\r\n\r\n\t\t\/\/ Number of unit to wait\r\n\t\t$wait = '10'; \/\/ integer.\r\n\r\n\t\t\/\/ Choose time unit.\r\n\t\t$unit = 'MINUTE'; \/\/ MINUTE, HOUR, DAY, WEEK, MONTH, YEAR.\r\n\r\n\t\t\/\/ Add SQL-sytax to default $where. By default 10 minutes.\r\n\t\t$where .= \" AND TIMESTAMPDIFF($unit, $wpdb->posts.post_date_gmt, '$now') > $wait \";\r\n\t}\r\n\r\n\treturn $where;\r\n}\r\n\r\nadd_filter( 'posts_where', 'wpcode_snippet_publish_later_on_feed' );","note":"Add a delay before published posts show up in the RSS feeds.","categories":["rss-feeds"],"code_type":"php","needs_auth":false},{"library_id":13025,"title":"Disable Admin Password Reset Emails","code":"remove_action( 'after_password_reset', 'wp_password_change_notification' );\r\n","note":"Don't send an email to the administrator of the site after a user resets their...","categories":["disable"],"code_type":"php","needs_auth":false},{"library_id":40,"title":"Disable Attachment Pages","code":"add_action(\r\n\t'template_redirect',\r\n\tfunction () {\r\n\t\tglobal $post;\r\n\t\tif ( ! is_attachment() || ! isset( $post->post_parent ) || ! is_numeric( $post->post_parent ) ) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t\/\/ Does the attachment have a parent post?\r\n\t\t\/\/ If the post is trashed, fallback to redirect to homepage.\r\n\t\tif ( 0 !== $post->post_parent && 'trash' !== get_post_status( $post->post_parent ) ) {\r\n\t\t\t\/\/ Redirect to the attachment parent.\r\n\t\t\twp_safe_redirect( get_permalink( $post->post_parent ), 301 );\r\n\t\t} else {\r\n\t\t\t\/\/ For attachment without a parent redirect to homepage.\r\n\t\t\twp_safe_redirect( get_bloginfo( 'wpurl' ), 302 );\r\n\t\t}\r\n\t\texit;\r\n\t},\r\n\t1\r\n);\r\n","note":"Hide the Attachment\/Attachments pages on the frontend from all visitors.","categories":["most-popular","attachments"],"code_type":"php","needs_auth":false},{"library_id":38,"title":"Disable Automatic Updates","code":"\/\/ Disable core auto-updates\r\nadd_filter( 'auto_update_core', '__return_false' );\r\n\/\/ Disable auto-updates for plugins.\r\nadd_filter( 'auto_update_plugin', '__return_false' );\r\n\/\/ Disable auto-updates for themes.\r\nadd_filter( 'auto_update_theme', '__return_false' );","note":"Use this snippet to completely disable automatic updates on your website.","categories":["most-popular","disable"],"code_type":"php","needs_auth":false},{"library_id":39,"title":"Disable Automatic Updates Emails","code":"\/\/ Disable auto-update emails.\r\nadd_filter( 'auto_core_update_send_email', '__return_false' );\r\n\r\n\/\/ Disable auto-update emails for plugins.\r\nadd_filter( 'auto_plugin_update_send_email', '__return_false' );\r\n\r\n\/\/ Disable auto-update emails for themes.\r\nadd_filter( 'auto_theme_update_send_email', '__return_false' );","note":"Stop getting emails about automatic updates on your WordPress site.","categories":["most-popular","disable"],"code_type":"php","needs_auth":false},{"library_id":967,"title":"Disable Comment Form Website URL","code":"add_filter( 'comment_form_default_fields', function ($fields) {\r\n\tif ( isset( $fields['url'] ) ) {\r\n\t\tunset( $fields['url'] );\r\n\t}\r\n\r\n\treturn $fields;\r\n}, 150 );","note":"Remove the Website URL field from the Comments form.","categories":["comments","disable"],"code_type":"php","needs_auth":false},{"library_id":899,"title":"Disable Embeds","code":"\/**\r\n * Disable all embeds in WordPress.\r\n *\/\r\nadd_action( 'init', function () {\r\n\r\n\t\/\/ Remove the REST API endpoint.\r\n\tremove_action( 'rest_api_init', 'wp_oembed_register_route' );\r\n\r\n\t\/\/ Turn off oEmbed auto discovery.\r\n\tadd_filter( 'embed_oembed_discover', '__return_false' );\r\n\r\n\t\/\/ Don't filter oEmbed results.\r\n\tremove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );\r\n\r\n\t\/\/ Remove oEmbed discovery links.\r\n\tremove_action( 'wp_head', 'wp_oembed_add_discovery_links' );\r\n\r\n\t\/\/ Remove oEmbed-specific JavaScript from the front-end and back-end.\r\n\tremove_action( 'wp_head', 'wp_oembed_add_host_js' );\r\n\tadd_filter( 'tiny_mce_plugins', function ( $plugins ) {\r\n\t\treturn array_diff( $plugins, array( 'wpembed' ) );\r\n\t} );\r\n\r\n\t\/\/ Remove all embeds rewrite rules.\r\n\tadd_filter( 'rewrite_rules_array', function ( $rules ) {\r\n\t\tforeach ( $rules as $rule => $rewrite ) {\r\n\t\t\tif ( false !== strpos( $rewrite, 'embed=true' ) ) {\r\n\t\t\t\tunset( $rules[ $rule ] );\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn $rules;\r\n\t} );\r\n\r\n\t\/\/ Remove filter of the oEmbed result before any HTTP requests are made.\r\n\tremove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 );\r\n}, 9999 );","note":"Remove an extra request and prevent others from adding embeds in your site.","categories":["disable"],"code_type":"php","needs_auth":false},{"library_id":897,"title":"Disable Emojis","code":"\/**\r\n * Disable the emojis in WordPress.\r\n *\/\r\nadd_action( 'init', function () {\r\n\tremove_action( 'wp_head', 'print_emoji_detection_script', 7 );\r\n\tremove_action( 'admin_print_scripts', 'print_emoji_detection_script' );\r\n\tremove_action( 'wp_print_styles', 'print_emoji_styles' );\r\n\tremove_action( 'admin_print_styles', 'print_emoji_styles' );\r\n\tremove_filter( 'the_content_feed', 'wp_staticize_emoji' );\r\n\tremove_filter( 'comment_text_rss', 'wp_staticize_emoji' );\r\n\tremove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );\r\n\r\n\t\/\/ Remove from TinyMCE.\r\n\tadd_filter( 'tiny_mce_plugins', function ( $plugins ) {\r\n\t\tif ( is_array( $plugins ) ) {\r\n\t\t\treturn array_diff( $plugins, array( 'wpemoji' ) );\r\n\t\t} else {\r\n\t\t\treturn array();\r\n\t\t}\r\n\t} );\r\n\r\n\t\/\/ Remove from dns-prefetch.\r\n\tadd_filter( 'wp_resource_hints', function ( $urls, $relation_type ) {\r\n\t\tif ( 'dns-prefetch' === $relation_type ) {\r\n\t\t\t$emoji_svg_url = apply_filters( 'emoji_svg_url', 'https:\/\/s.w.org\/images\/core\/emoji\/2\/svg\/' );\r\n\t\t\t$urls = array_diff( $urls, array( $emoji_svg_url ) );\r\n\t\t}\r\n\r\n\t\treturn $urls;\r\n\t}, 10, 2 );\r\n} );\r\n","note":"Disable Emoji's in WordPress to improve your site's performance","categories":["disable"],"code_type":"php","needs_auth":false},{"library_id":13023,"title":"Disable Fullscreen Editor","code":"add_action(\r\n\t'enqueue_block_editor_assets',\r\n\tfunction () {\r\n\t\t$script = \"jQuery( window ).load(function() { const isFullscreenMode = wp.data.select( 'core\/edit-post' ).isFeatureActive( 'fullscreenMode' ); if ( isFullscreenMode ) { wp.data.dispatch( 'core\/edit-post' ).toggleFeature( 'fullscreenMode' ); } });\";\r\n\t\twp_add_inline_script( 'wp-blocks', $script );\r\n\t}\r\n);","note":"Automatically disable the Gutenberg Fullscreen editor for all users.","categories":["admin","disable"],"code_type":"php","needs_auth":false},{"library_id":1193,"title":"Disable Gutenberg Code Editing for Non-Admin Users","code":"add_filter( 'block_editor_settings_all', function ( $settings ) {\r\n\t\r\n\t$settings['codeEditingEnabled'] = current_user_can( 'manage_options' );\r\n\r\n\treturn $settings;\r\n} );","note":"Prevent non-admin users from using \"Edit as HTML\" or \"Code editor\" in the Gutenberg Editor.","categories":["admin","disable"],"code_type":"php","needs_auth":false},{"library_id":14,"title":"Disable Gutenberg Editor (use Classic Editor)","code":"add_filter('gutenberg_can_edit_post', '__return_false', 5);\r\nadd_filter('use_block_editor_for_post', '__return_false', 5);","note":"Switch back to the Classic Editor by disablling the Block Editor.","categories":["most-popular","admin"],"code_type":"php","needs_auth":false},{"library_id":6004,"title":"Disable Lazy Load","code":"add_filter( 'wp_lazy_loading_enabled', '__return_false' );\r\n","note":"Prevent WordPress from adding the lazy-load attribute to all images and iframes.","categories":["attachments","disable"],"code_type":"php","needs_auth":false},{"library_id":13027,"title":"Disable Login Autofocus","code":"add_filter( 'enable_login_autofocus', '__return_false' );","note":"Prevent autofocus on the username field on the login page.","categories":["disable","login"],"code_type":"php","needs_auth":false},{"library_id":46,"title":"Disable Login by Email","code":"remove_filter( 'authenticate', 'wp_authenticate_email_password', 20 );","note":"Force your users to login only using their username.","categories":["login"],"code_type":"php","needs_auth":false},{"library_id":60,"title":"Disable Login Screen Language Switcher","code":"add_filter( 'login_display_language_dropdown', '__return_false' );","note":"Hide the Language Switcher on the default WordPress login screen.","categories":["login"],"code_type":"php","needs_auth":false},{"library_id":962,"title":"Disable New User Notifications","code":"function wpcode_send_new_user_notifications( $user_id, $notify = 'user' ) {\r\n\tif ( empty( $notify ) || 'admin' === $notify ) {\r\n\t\treturn;\r\n\t} elseif ( 'both' === $notify ) {\r\n\t\t\/\/ Send new users the email but not the admin.\r\n\t\t$notify = 'user';\r\n\t}\r\n\twp_send_new_user_notifications( $user_id, $notify );\r\n}\r\n\r\nadd_action(\r\n\t'init',\r\n\tfunction () {\r\n\t\t\/\/ Disable default email notifications.\r\n\t\tremove_action( 'register_new_user', 'wp_send_new_user_notifications' );\r\n\t\tremove_action( 'edit_user_created_user', 'wp_send_new_user_notifications' );\r\n\r\n\t\t\/\/ Replace with custom function that only sends to user.\r\n\t\tadd_action( 'register_new_user', 'wpcode_send_new_user_notifications' );\r\n\t\tadd_action( 'edit_user_created_user', 'wpcode_send_new_user_notifications', 10, 2 );\r\n\t}\r\n);\r\n","note":"Prevent the admin user from getting new user notification emails.","categories":["disable"],"code_type":"php","needs_auth":false},{"library_id":6011,"title":"Disable Plugin & Theme Editor","code":"\/\/ Disable the Plugin and Theme Editor\r\nif ( ! defined( 'DISALLOW_FILE_EDIT' ) ) {\r\n\tdefine( 'DISALLOW_FILE_EDIT', true );\r\n}\r\n","note":"Prevent users from using the Plugin & Theme file editor.","categories":["admin","disable"],"code_type":"php","needs_auth":false},{"library_id":6568,"title":"Disable REST API Links","code":"remove_action( 'xmlrpc_rsd_apis', 'rest_output_rsd' );\r\nremove_action( 'wp_head', 'rest_output_link_wp_head' );\r\nremove_action( 'template_redirect', 'rest_output_link_header', 11 );","note":"Remove all head links to the REST API endpoints from the page source.","categories":["disable"],"code_type":"php","needs_auth":false},{"library_id":6564,"title":"Disable RSS Feed Links","code":"remove_action('wp_head', 'feed_links', 2 );\r\nremove_action('wp_head', 'feed_links_extra', 3 );","note":"Remove head links to RSS Feeds from all the pages on your site.","categories":["rss-feeds"],"code_type":"php","needs_auth":false},{"library_id":41,"title":"Disable RSS Feeds","code":"\/**\r\n * Display a custom message instead of the RSS Feeds.\r\n *\r\n * @return void\r\n *\/\r\nfunction wpcode_snippet_disable_feed() {\r\n\twp_die(\r\n\t\tsprintf(\r\n\t\t\t\/\/ Translators: Placeholders for the homepage link.\r\n\t\t\tesc_html__( 'No feed available, please visit our %1$shomepage%2$s!' ),\r\n\t\t\t' <a href=\"' . esc_url( home_url( '\/' ) ) . '\">',\r\n\t\t\t'<\/a>'\r\n\t\t)\r\n\t);\r\n}\r\n\r\n\/\/ Replace all feeds with the message above.\r\nadd_action( 'do_feed_rdf', 'wpcode_snippet_disable_feed', 1 );\r\nadd_action( 'do_feed_rss', 'wpcode_snippet_disable_feed', 1 );\r\nadd_action( 'do_feed_rss2', 'wpcode_snippet_disable_feed', 1 );\r\nadd_action( 'do_feed_atom', 'wpcode_snippet_disable_feed', 1 );\r\nadd_action( 'do_feed_rss2_comments', 'wpcode_snippet_disable_feed', 1 );\r\nadd_action( 'do_feed_atom_comments', 'wpcode_snippet_disable_feed', 1 );\r\n\/\/ Remove links to feed from the header.\r\nremove_action( 'wp_head', 'feed_links_extra', 3 );\r\nremove_action( 'wp_head', 'feed_links', 2 );\r\n","note":"Turn off the WordPress RSS Feeds for your website with 1 click.","categories":["rss-feeds"],"code_type":"php","needs_auth":false},{"library_id":47,"title":"Disable Search","code":"\/\/ Prevent search queries.\r\nadd_action(\r\n\t'parse_query',\r\n\tfunction ( $query, $error = true ) {\r\n\t\tif ( is_search() && ! is_admin() ) {\r\n\t\t\t$query->is_search = false;\r\n\t\t\t$query->query_vars['s'] = false;\r\n\t\t\t$query->query['s'] = false;\r\n\t\t\tif ( true === $error ) {\r\n\t\t\t\t$query->is_404 = true;\r\n\t\t\t}\r\n\t\t}\r\n\t},\r\n\t15,\r\n\t2\r\n);\r\n\r\n\/\/ Remove the Search Widget.\r\nadd_action(\r\n\t'widgets_init',\r\n\tfunction () {\r\n\t\tunregister_widget( 'WP_Widget_Search' );\r\n\t}\r\n);\r\n\r\n\/\/ Remove the search form.\r\nadd_filter( 'get_search_form', '__return_empty_string', 999 );\r\n\r\n\/\/ Remove the core search block.\r\nadd_action(\r\n\t'init',\r\n\tfunction () {\r\n\t\tif ( ! function_exists( 'unregister_block_type' ) || ! class_exists( 'WP_Block_Type_Registry' ) ) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t$block = 'core\/search';\r\n\t\tif ( WP_Block_Type_Registry::get_instance()->is_registered( $block ) ) {\r\n\t\t\tunregister_block_type( $block );\r\n\t\t}\r\n\t}\r\n);\r\n\r\n\/\/ Remove admin bar menu search box.\r\nadd_action(\r\n\t'admin_bar_menu',\r\n\tfunction ( $wp_admin_bar ) {\r\n\t\t$wp_admin_bar->remove_menu( 'search' );\r\n\t},\r\n\t11\r\n);\r\n","note":"Completely disable search on your WordPress website.","categories":["disable"],"code_type":"php","needs_auth":false},{"library_id":955,"title":"Disable Self Pingbacks","code":"add_action( 'pre_ping', function( &$links ) {\r\n\t$home = get_option( 'home' );\r\n\tforeach ( $links as $l => $link ) {\r\n\t\tif ( 0 === strpos( $link, $home ) ) {\r\n\t\t\tunset( $links[ $l ] );\r\n\t\t}\r\n\t}\r\n} );\r\n","note":"Prevent WordPress from automatically creating pingbacks from your own site.","categories":["disable"],"code_type":"php","needs_auth":false},{"library_id":6006,"title":"Disable Site Health","code":"\/\/ Remove Tools Submenu Item for Site Health.\r\nadd_action( 'admin_menu', function () {\r\n\tremove_submenu_page( 'tools.php', 'site-health.php' );\r\n} );\r\n\r\n\/\/ Prevent direct access to the Site Health page.\r\nadd_action( 'current_screen', function () {\r\n\t$screen = get_current_screen();\r\n\tif ( 'site-health' === $screen->id ) {\r\n\t\twp_safe_redirect( admin_url() );\r\n\t\texit;\r\n\t}\r\n} );\r\n\r\n\/\/ Disable the Site Health Dashboard Widget.\r\nadd_action( 'wp_dashboard_setup', function () {\r\n\tglobal $wp_meta_boxes;\r\n\tif ( isset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_site_health'] ) ) {\r\n\t\tunset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_site_health'] );\r\n\t}\r\n} );\r\n","note":"Completely hide the Site Health menu item and dashboard widget.","categories":["admin","disable"],"code_type":"php","needs_auth":false},{"library_id":6566,"title":"Disable the WordPress Shortlink","code":"remove_action('wp_head', 'wp_shortlink_wp_head' );\r\n","note":"Remove link rel shortlink from your site head area.","categories":["archive","disable"],"code_type":"php","needs_auth":false},{"library_id":42,"title":"Disable The WP Admin Bar","code":"\/* Disable WordPress Admin Bar for all users *\/\r\nadd_filter( 'show_admin_bar', '__return_false' );","note":"Hide the WordPress Admin Bar for all users in the frontend.","categories":["most-popular","admin"],"code_type":"php","needs_auth":false},{"library_id":13029,"title":"Disable Update Notice for Non-admin Users","code":"add_action( 'admin_head', function () {\r\n\tif ( current_user_can( 'update_core' ) ) {\r\n\t\treturn;\r\n\t}\r\n\tremove_action( 'admin_notices', 'update_nag', 3 );\r\n}, 1 );","note":"Don't show WordPress version update notices to users that can't update the site.","categories":["admin","disable"],"code_type":"php","needs_auth":false},{"library_id":35,"title":"Disable Widget Blocks (use Classic Widgets)","code":"add_filter( 'use_widgets_block_editor', '__return_false' );","note":"Use the classic interface instead of Blocks to manage Widgets.","categories":["most-popular","widgets"],"code_type":"php","needs_auth":false},{"library_id":953,"title":"Disable wlwmanifest link","code":"remove_action('wp_head', 'wlwmanifest_link');\r\n","note":"Prevent WordPress from adding the Windows Live Writer manifest link to your pages.","categories":["disable"],"code_type":"php","needs_auth":false},{"library_id":37,"title":"Disable WordPress REST API","code":"add_filter(\r\n\t'rest_authentication_errors',\r\n\tfunction ( $access ) {\r\n\t\treturn new WP_Error(\r\n\t\t\t'rest_disabled',\r\n\t\t\t__( 'The WordPress REST API has been disabled.' ),\r\n\t\t\tarray(\r\n\t\t\t\t'status' => rest_authorization_required_code(),\r\n\t\t\t)\r\n\t\t);\r\n\t}\r\n);","note":"Easily disable the WP REST API on your website with this snippet.","categories":["most-popular","disable"],"code_type":"php","needs_auth":false},{"library_id":6009,"title":"Disable WordPress Sitemaps","code":"add_filter('wp_sitemaps_enabled', '__return_false');\r\n","note":"Disable the auto-generated WordPress Sitemaps added in version 5.5.","categories":["disable"],"code_type":"php","needs_auth":false},{"library_id":55,"title":"Disable XML-RPC","code":"add_filter( 'xmlrpc_enabled', '__return_false' );\r\n","note":"On sites running WordPress 3.5+, disable XML-RPC completely.","categories":["most-popular","disable"],"code_type":"php","needs_auth":false},{"library_id":62,"title":"Display the Last Updated Date","code":"$u_time = get_the_time( 'U' );\r\n$u_modified_time = get_the_modified_time( 'U' );\r\n\/\/ Only display modified date if 24hrs have passed since the post was published.\r\nif ( $u_modified_time >= $u_time + 86400 ) {\r\n\r\n\t$updated_date = get_the_modified_time( 'F jS, Y' );\r\n\t$updated_time = get_the_modified_time( 'h:i a' );\r\n\r\n\t$updated = '<p class=\"last-updated\">';\r\n\r\n\t$updated .= sprintf(\r\n\t\/\/ Translators: Placeholders get replaced with the date and time when the post was modified.\r\n\t\tesc_html__( 'Last updated on %1$s at %2$s' ),\r\n\t\t$updated_date,\r\n\t\t$updated_time\r\n\t);\r\n\t$updated .= '<\/p>';\r\n\r\n\techo wp_kses_post( $updated );\r\n}\r\n","note":"Add the last updated date & time to your posts in the frontend.","categories":["archive"],"code_type":"php","needs_auth":false},{"library_id":1196,"title":"Duplicate Post\/Page Link","code":"\/\/ Add duplicate button to post\/page list of actions.\r\nadd_filter( 'post_row_actions', 'wpcode_snippet_duplicate_post_link', 10, 2 );\r\nadd_filter( 'page_row_actions', 'wpcode_snippet_duplicate_post_link', 10, 2 );\r\n\r\n\/\/ Let's make sure the function doesn't already exist.\r\nif ( ! function_exists( 'wpcode_snippet_duplicate_post_link' ) ) {\r\n\t\/**\r\n\t * @param array $actions The actions added as links to the admin.\r\n\t * @param WP_Post $post The post object.\r\n\t *\r\n\t * @return array\r\n\t *\/\r\n\tfunction wpcode_snippet_duplicate_post_link( $actions, $post ) {\r\n\r\n\t\t\/\/ Don't add action if the current user can't create posts of this post type.\r\n\t\t$post_type_object = get_post_type_object( $post->post_type );\r\n\r\n\t\tif ( null === $post_type_object || ! current_user_can( $post_type_object->cap->create_posts ) ) {\r\n\t\t\treturn $actions;\r\n\t\t}\r\n\r\n\r\n\t\t$url = wp_nonce_url(\r\n\t\t\tadd_query_arg(\r\n\t\t\t\tarray(\r\n\t\t\t\t\t'action' => 'wpcode_snippet_duplicate_post',\r\n\t\t\t\t\t'post_id' => $post->ID,\r\n\t\t\t\t),\r\n\t\t\t\t'admin.php'\r\n\t\t\t),\r\n\t\t\t'wpcode_duplicate_post_' . $post->ID,\r\n\t\t\t'wpcode_duplicate_nonce'\r\n\t\t);\r\n\r\n\t\t$actions['wpcode_duplicate'] = '<a href=\"' . $url . '\" title=\"Duplicate item\" rel=\"permalink\">Duplicate<\/a>';\r\n\r\n\t\treturn $actions;\r\n\t}\r\n}\r\n\r\n\/**\r\n * Handle the custom action when clicking the button we added above.\r\n *\/\r\nadd_action( 'admin_action_wpcode_snippet_duplicate_post', function () {\r\n\r\n\tif ( empty( $_GET['post_id'] ) ) {\r\n\t\twp_die( 'No post id set for the duplicate action.' );\r\n\t}\r\n\r\n\t$post_id = absint( $_GET['post_id'] );\r\n\r\n\t\/\/ Check the nonce specific to the post we are duplicating.\r\n\tif ( ! isset( $_GET['wpcode_duplicate_nonce'] ) || ! wp_verify_nonce( $_GET['wpcode_duplicate_nonce'], 'wpcode_duplicate_post_' . $post_id ) ) {\r\n\t\t\/\/ Display a message if the nonce is invalid, may it expired.\r\n\t\twp_die( 'The link you followed has expired, please try again.' );\r\n\t}\r\n\r\n\t\/\/ Load the post we want to duplicate.\r\n\t$post = get_post( $post_id );\r\n\r\n\t\/\/ Create a new post data array from the post loaded.\r\n\tif ( $post ) {\r\n\t\t$current_user = wp_get_current_user();\r\n\t\t$new_post = array(\r\n\t\t\t'comment_status' => $post->comment_status,\r\n\t\t\t'menu_order' => $post->menu_order,\r\n\t\t\t'ping_status' => $post->ping_status,\r\n\t\t\t'post_author' => $current_user->ID,\r\n\t\t\t'post_content' => $post->post_content,\r\n\t\t\t'post_excerpt' => $post->post_excerpt,\r\n\t\t\t'post_name' => $post->post_name,\r\n\t\t\t'post_parent' => $post->post_parent,\r\n\t\t\t'post_password' => $post->post_password,\r\n\t\t\t'post_status' => 'draft',\r\n\t\t\t'post_title' => $post->post_title . ' (copy)',\/\/ Add \"(copy)\" to the title.\r\n\t\t\t'post_type' => $post->post_type,\r\n\t\t\t'to_ping' => $post->to_ping,\r\n\t\t);\r\n\t\t\/\/ Create the new post\r\n\t\t$duplicate_id = wp_insert_post( $new_post );\r\n\t\t\/\/ Copy the taxonomy terms.\r\n\t\t$taxonomies = get_object_taxonomies( get_post_type( $post ) );\r\n\t\tif ( $taxonomies ) {\r\n\t\t\tforeach ( $taxonomies as $taxonomy ) {\r\n\t\t\t\t$post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'slugs' ) );\r\n\t\t\t\twp_set_object_terms( $duplicate_id, $post_terms, $taxonomy );\r\n\t\t\t}\r\n\t\t}\r\n\t\t\/\/ Copy all the custom fields.\r\n\t\t$post_meta = get_post_meta( $post_id );\r\n\t\tif ( $post_meta ) {\r\n\r\n\t\t\tforeach ( $post_meta as $meta_key => $meta_values ) {\r\n\t\t\t\tif ( '_wp_old_slug' === $meta_key ) { \/\/ skip old slug.\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tforeach ( $meta_values as $meta_value ) {\r\n\t\t\t\t\tadd_post_meta( $duplicate_id, $meta_key, $meta_value );\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t\/\/ Redirect to edit the new post.\r\n\t\twp_safe_redirect(\r\n\t\t\tadd_query_arg(\r\n\t\t\t\tarray(\r\n\t\t\t\t\t'action' => 'edit',\r\n\t\t\t\t\t'post' => $duplicate_id\r\n\t\t\t\t),\r\n\t\t\t\tadmin_url( 'post.php' )\r\n\t\t\t)\r\n\t\t);\r\n\t\texit;\r\n\t} else {\r\n\t\twp_die( 'Error loading post for duplication, please try again.' );\r\n\t}\r\n} );\r\n","note":"Duplicate posts, pages or any post type with 1-click by adding a duplicate link in...","categories":["most-popular","admin"],"code_type":"php","needs_auth":false},{"library_id":6002,"title":"Dynamic Year Copyright Shortcode","code":"\/\/ Copy the Shortcode in the Insertion box below and paste it wherever you want the copyright symbol + year to be displayed.\r\n\/\/ This will output \u00a9 2023 or the current year automatically.\r\necho \"© \" . date( 'Y' );","note":"This snippet adds an easy-to-use shortcode to display the copyright symbol with the current year.","categories":["archive"],"code_type":"php","needs_auth":false},{"library_id":6013,"title":"Empty Admin Dashboard","code":"add_action( 'wp_dashboard_setup', function () {\r\n\tglobal $wp_meta_boxes;\r\n\t$wp_meta_boxes['dashboard'] = array();\r\n\tremove_action( 'welcome_panel', 'wp_welcome_panel' );\r\n} );","note":"Disable all dashboard widgets in the admin and the welcome panel.","categories":["admin","disable"],"code_type":"php","needs_auth":false},{"library_id":53,"title":"Enable Shortcode Execution in Text Widgets","code":"add_filter( 'widget_text', 'do_shortcode' );","note":"Extend the default Text Widget with shortcode execution.","categories":["widgets"],"code_type":"php","needs_auth":false},{"library_id":4152,"title":"Enable Shortcode Execution in WPCode HTML Snippets","code":"add_filter( 'wpcode_snippet_output_html', 'do_shortcode' );","note":"Use this snippet to enable shortcode execution in WPCode HTML snippets.","categories":["archive"],"code_type":"php","needs_auth":false},{"library_id":52,"title":"Exclude Specific Categories from RSS Feed","code":"\/**\r\n * Exclude a category or multiple categories from the feeds.\r\n * If you want to exclude multiple categories, use a comma-separated list: \"-15, -5, -6\".\r\n * Make sure to prefix the category id(s) with a minus \"-\".\r\n *\r\n * @param WP_Query $query The query.\r\n *\/\r\nfunction wpcode_snippets_exclude_feed_category( $query ) {\r\n\tif ( $query->is_feed ) {\r\n\t\t\/\/ Replace 15 with the desired category id you want to exclude.\r\n\t\t$query->set( 'cat', '-15' );\r\n\t}\r\n}\r\n\r\nadd_action( 'pre_get_posts', 'wpcode_snippets_exclude_feed_category' );\r\n","note":"Prevent posts in certain categories from showing up in your RSS Feeds.","categories":["rss-feeds"],"code_type":"php","needs_auth":false},{"library_id":19,"title":"Hide \u2018Screen Options\u2019 Tab","code":"\/\/ Hide admin 'Screen Options' tab\r\nadd_filter('screen_options_show_screen', '__return_false');","note":"Remove the Screen Options menu at the top of admin pages.","categories":["admin"],"code_type":"php","needs_auth":false},{"library_id":45,"title":"Hide Login Errors in WordPress","code":"add_filter(\r\n\t'login_errors',\r\n\tfunction ( $error ) {\r\n\t\t\/\/ Edit the line below to customize the message.\r\n\t\treturn 'Something is wrong!';\r\n\t}\r\n);\r\n","note":"Improve safety by hiding the specific login error information.","categories":["login"],"code_type":"php","needs_auth":false},{"library_id":6570,"title":"Limit the Number of Post Revisions","code":"add_filter( 'wp_revisions_to_keep', function( $limit ) {\r\n\t\/\/ Limit to the last 20 revisions. Change 20 to whatever limit you want.\r\n\treturn 20;\r\n} );","note":"Reduce Database size by limiting post revisions to just 20 per post.","categories":["admin"],"code_type":"php","needs_auth":false},{"library_id":957,"title":"Lowercase Filenames for Uploads","code":"add_filter( 'sanitize_file_name', 'mb_strtolower' );","note":"Make all the filenames of new uploads to lowercase after you enable this snippet.","categories":["attachments"],"code_type":"php","needs_auth":false},{"library_id":51,"title":"Remove Dashboard Welcome Panel","code":"add_action(\r\n\t'admin_init',\r\n\tfunction () {\r\n\t\tremove_action( 'welcome_panel', 'wp_welcome_panel' );\r\n\t}\r\n);\r\n","note":"Hide the Welcome Panel on the WordPress dashboard for all users.","categories":["admin"],"code_type":"php","needs_auth":false},{"library_id":969,"title":"Remove Login Shake Animation","code":"add_action( 'login_footer', function () {\r\n\tremove_action( 'login_footer', 'wp_shake_js', 12 );\r\n} );","note":"Prevent the Login box from shaking when entering the wrong password or username.","categories":["disable","login"],"code_type":"php","needs_auth":false},{"library_id":950,"title":"Remove Query Strings From Static Files","code":"function wpcode_snippet_remove_query_strings_split( $src ) {\r\n\t$output = preg_split( \"\/(&ver|\\\\?ver)\/\", $src );\r\n\r\n\treturn $output ? $output[0] : '';\r\n}\r\n\r\nadd_action( 'init', function () {\r\n\tif ( ! is_admin() ) {\r\n\t\tadd_filter( 'script_loader_src', 'wpcode_snippet_remove_query_strings_split', 15 );\r\n\t\tadd_filter( 'style_loader_src', 'wpcode_snippet_remove_query_strings_split', 15 );\r\n\t}\r\n} );","note":"Use this snippet to remove query string from CSS & JS files and improve performance...","categories":["attachments","disable"],"code_type":"php","needs_auth":false},{"library_id":13031,"title":"Remove the WordPress Logo From the Admin Bar","code":"add_action( 'wp_before_admin_bar_render', function () {\r\n\tglobal $wp_admin_bar;\r\n\t$wp_admin_bar->remove_menu( 'wp-logo' );\r\n}, 0 );","note":"Hide the WordPress logo in the admin bar for all users.","categories":["disable"],"code_type":"php","needs_auth":false},{"library_id":36,"title":"Remove WordPress Version Number","code":"add_filter('the_generator', '__return_empty_string');\r\n","note":"Hide the WordPress version number from your site's frontend and feeds.","categories":["most-popular","disable"],"code_type":"php","needs_auth":false},{"library_id":959,"title":"Replace WordPress Logo on Login Page","code":"add_filter( 'login_head', function () {\r\n\t\/\/ Update the line below with the URL to your own logo.\r\n\t\/\/ Adjust the Width & Height accordingly.\r\n\t$custom_logo = 'https:\/\/wpcode.com\/wp-admin\/images\/wordpress-logo.svg';\r\n\t$logo_width = 84;\r\n\t$logo_height = 84;\r\n\r\n\tprintf(\r\n\t\t'<style>.login h1 a {background-image:url(%1$s) !important; margin:0 auto; width: %2$spx; height: %3$spx; background-size: 100%%;}<\/style>',\r\n\t\t$custom_logo,\r\n\t\t$logo_width,\r\n\t\t$logo_height\r\n\t);\r\n}, 990 );","note":"Use your custom logo on the default login page, don't forget to edit the snippet...","categories":["login"],"code_type":"php","needs_auth":false},{"library_id":59,"title":"Set a Minimum Word Count for Posts","code":"\/**\r\n * Prevent publishing posts under a minimum number of words.\r\n *\r\n * @param int $post_id The id of the post.\r\n * @param WP_Post $post The post object.\r\n *\r\n * @return void\r\n *\/\r\nfunction wpcode_snippet_publish_min_words( $post_id, $post ) {\r\n\t\/\/ Edit the line below to set the desired minimum number of words.\r\n\t$word_count = 100;\r\n\r\n\tif ( str_word_count( $post->post_content ) < $word_count ) {\r\n\t\twp_die(\r\n\t\t\tsprintf(\r\n\t\t\t\t\/\/ Translators: placeholder adds the minimum number of words.\r\n\t\t\t\tesc_html__( 'The post content is below the minimum word count. Your post needs to have at least %d words to be published.' ),\r\n\t\t\t\tabsint( $word_count )\r\n\t\t\t)\r\n\t\t);\r\n\t}\r\n}\r\n\r\nadd_action( 'publish_post', 'wpcode_snippet_publish_min_words', 9, 2 );","note":"Force your authors to write posts that have a minimum length.","categories":["admin"],"code_type":"php","needs_auth":false},{"library_id":61,"title":"Set oEmbed Max Width","code":"function wpcode_snippet_oembed_defaults( $sizes ) {\r\n\treturn array(\r\n\t\t'width' => 400,\r\n\t\t'height' => 280,\r\n\t);\r\n}\r\n\r\nadd_filter( 'embed_defaults', 'wpcode_snippet_oembed_defaults' );\r\n","note":"Set a max width for the embeds using oEmbed in the content.","categories":["admin"],"code_type":"php","needs_auth":false}],"links":{"snippet":"https:\/\/library.wpcode.com\/api\/get\/"}}