File: /home/creaqbdc/public_html/wp-content/uploads/wpcode/cache/library/snippets.json
{"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":22997,"title":"\"New\" Badge for Recent Posts","code":"add_filter( 'the_title', function ( $title, $id ) {\r\n\tif ( ! is_admin() && is_single( $id ) ) {\r\n\t\t$number_of_days = 7;\r\n\t\t$post_date = get_the_date( 'U', $id );\r\n\t\t$current_date = current_time( 'timestamp' );\r\n\t\t$date_diff = $current_date - $post_date;\r\n\r\n\t\tif ( $date_diff < $number_of_days * DAY_IN_SECONDS ) {\r\n\t\t\t$title .= ' <span class=\"new-badge\">New<\/span>';\r\n\t\t}\r\n\t}\r\n\r\n\treturn $title;\r\n}, 10, 2 );\r\n\r\nadd_action( 'wp_head', function () {\r\n\techo '\r\n <style>\r\n .new-badge {\r\n background-color: #ff0000; \r\n color: #ffffff; \r\n padding: 2px 5px; \r\n font-size: 12px; \r\n border-radius: 3px;\r\n margin-left: 5px;\r\n }\r\n <\/style>\r\n ';\r\n} );\r\n","note":"Display a badge to highlight posts that are newer than 7 days.","categories":["archive"],"code_type":"php","needs_auth":false},{"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":21342,"title":"Add Auto Sizes to Lazy Loaded images","code":"add_filter( 'wp_get_attachment_image_attributes', function( $attr ) {\r\n\tif ( ! isset( $attr['loading'] ) || 'lazy' !== $attr['loading'] || ! isset( $attr['sizes'] ) ) {\r\n\t\treturn $attr;\r\n\t}\r\n\t\r\n\t\/\/ Skip if attribute was already added.\r\n\tif ( false !== strpos( $attr['sizes'], 'auto,' ) ) {\r\n\t\treturn $attr;\r\n\t}\r\n\r\n\t$attr['sizes'] = 'auto, ' . $attr['sizes'];\r\n\r\n\treturn $attr;\r\n} );\r\n\r\nadd_filter( 'wp_content_img_tag', function( $html ) {\r\n\tif (false === strpos($html, 'loading=\"lazy\"') || (false === strpos($html, 'sizes=\"') || false !== strpos($html, 'sizes=\"auto,'))) {\r\n\t\treturn $html;\r\n\t}\r\n\r\n\t$html = str_replace( 'sizes=\"', 'sizes=\"auto, ', $html );\r\n\r\n\treturn $html;\r\n} );","note":"Use the \"auto\" size added in browsers for lazy loaded images.","categories":["attachments"],"code_type":"php","needs_auth":false},{"library_id":28377,"title":"Add basic Open Graph Tags","code":"<meta property=\"og:title\" content=\"<?php echo esc_attr( get_the_title() ); ?>\"\/>\r\n<meta property=\"og:description\" content=\"<?php echo esc_attr( get_the_excerpt() ); ?>\"\/>\r\n<meta property=\"og:url\" content=\"<?php echo esc_attr( get_permalink() ); ?>\"\/>\r\n<meta property=\"og:type\" content=\"article\"\/>\r\n<?php if ( has_post_thumbnail() ) : ?>\r\n<meta property=\"og:image\" content=\"<?php echo esc_attr( get_the_post_thumbnail_url() ); ?>\"\/>\r\n<?php endif; ?>","note":"Add OG tags for social media in your posts and pages.","categories":["widgets"],"code_type":"universal","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":16240,"title":"Add ID column in admin tables","code":"add_action( 'admin_init', function () {\r\n\/\/ Get all public post types\r\n\t$post_types = get_post_types( array(), 'names' );\r\n\r\n\tfunction wpcode_add_post_id_column( $columns ) {\r\n\t\t$columns['wpcode_post_id'] = 'ID'; \/\/ 'ID' is the column title\r\n\r\n\t\treturn $columns;\r\n\t}\r\n\r\n\tfunction wpcode_show_post_id_column_data( $column, $post_id ) {\r\n\t\tif ( 'wpcode_post_id' === $column ) {\r\n\t\t\techo '<code>' . absint( $post_id ) . '<\/code>';\r\n\t\t}\r\n\t}\r\n\r\n\tforeach ( $post_types as $post_type ) {\r\n\t\t\/\/ Add new column to the posts list\r\n\t\tadd_filter( \"manage_{$post_type}_posts_columns\", 'wpcode_add_post_id_column' );\r\n\r\n\t\t\/\/ Fill the new column with the post ID\r\n\t\tadd_action( \"manage_{$post_type}_posts_custom_column\", 'wpcode_show_post_id_column_data', 10, 2 );\r\n\t}\r\n} );","note":"Display the post id in the admin in its own column for convenience.","categories":["admin"],"code_type":"php","needs_auth":false},{"library_id":33964,"title":"Add Last Modified Column","code":"add_filter( 'manage_posts_columns', function ( $columns ) {\r\n\t$columns['last_modified'] = __( 'Last Modified' );\r\n\treturn $columns;\r\n} );\r\n\r\nadd_action( 'manage_posts_custom_column', function ( $column, $post_id ) {\r\n\tif ( 'last_modified' === $column ) {\r\n\t\t$modified_time = get_the_modified_time( 'Y\/m\/d g:i:s a', $post_id );\r\n\t\techo esc_html( $modified_time );\r\n\t}\r\n}, 10, 2 );","note":"Display the post last modified date in the admin.","categories":["admin"],"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":18695,"title":"Add SEO-friendly Breadcrumbs","code":"\/\/ You can also use this snippet as a shortcode for more control.\r\nglobal $post;\r\nif ( ! is_home() ) {\r\n\techo '<div class=\"breadcrumbs\">';\r\n\techo '<a href=\"' . esc_url( site_url() ) . '\">Home<\/a> \/ ';\r\n\tif ( is_category() || is_single() ) {\r\n\t\tthe_category( ' \/ ' );\r\n\t\tif ( is_single() ) {\r\n\t\t\techo ' \/ ';\r\n\t\t\tthe_title();\r\n\t\t}\r\n\t} elseif ( is_page() ) {\r\n\t\tif ( $post->post_parent ) {\r\n\t\t\t$anc = get_post_ancestors( $post->ID );\r\n\t\t\t$page_title = get_the_title();\r\n\t\t\tforeach ( $anc as $ancestor ) {\r\n\t\t\t\techo '<a href=\"' . esc_url( get_permalink( $ancestor ) ) . '\" title=\"' . esc_attr( get_the_title( $ancestor ) ) . '\">' . esc_html( get_the_title( $ancestor ) ) . '<\/a> \/ ';\r\n\t\t\t}\r\n\t\t\techo esc_html( $page_title );\r\n\t\t} else {\r\n\t\t\techo '<strong> ' . esc_html( get_the_title() ) . '<\/strong>';\r\n\t\t}\r\n\t}\r\n\techo '<\/div>';\r\n}","note":"Automatically add SEO-friendly Breadcrumbs before posts or use as a shortcode for more control.","categories":["archive"],"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":18693,"title":"Allow Contributors to Upload Images","code":"add_filter( 'user_has_cap', function ( $allcaps, $caps, $args, $user ) {\r\n\tif ( in_array( 'contributor', $user->roles ) && empty( $caps['upload_files'] ) ) {\r\n\t\t$allcaps['upload_files'] = true;\r\n\t}\r\n\r\n\treturn $allcaps;\r\n}, 10, 4 );","note":"Allow users with the Contributor role to upload files in the admin.","categories":["attachments"],"code_type":"php","needs_auth":false},{"library_id":25491,"title":"Allow Only Logged-In Users","code":"add_action(\r\n\t'wp',\r\n\tstatic function () {\r\n\t\tif ( is_user_logged_in() ) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t\/\/ Handle API requests separately.\r\n\t\tif ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t\/\/ Allow access to the login screens.\r\n\t\t$allowed = array(\r\n\t\t\t'wp-login.php' => true,\r\n\t\t\t'wp-signup.php' => true,\r\n\t\t\t'wp-activate.php' => true,\r\n\t\t\t'wp-trackback.php' => true,\r\n\t\t\t'wp-cron.php' => true,\r\n\t\t);\r\n\t\tif ( isset( $allowed[ basename( $_SERVER['PHP_SELF'] ) ] ) ) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tnocache_headers();\r\n\t\twp_safe_redirect(\r\n\t\t\twp_login_url(\r\n\t\t\t\tset_url_scheme( 'http:\/\/' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] )\r\n\t\t\t)\r\n\t\t);\r\n\t\texit;\r\n\t}\r\n);\r\n\r\n\/\/ Custom Login error.\r\nadd_action(\r\n\t'init',\r\n\tstatic function () {\r\n\t\tglobal $error;\r\n\r\n\t\tif ( 'wp-login.php' !== basename( $_SERVER['PHP_SELF'] ) || ! empty( $_POST ) || ( ! empty( $_GET ) && empty( $_GET['redirect_to'] ) ) ) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t$redirect = isset( $_GET['redirect_to'] ) ? $_GET['redirect_to'] : '';\r\n\t\tif ( ! $redirect || str_starts_with( $redirect, admin_url() ) ) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t$error = __( 'You need to login to access this website.' );\r\n\t}\r\n);\r\n\r\n\/\/ Force logged-in only traffic for the API.\r\nadd_filter(\r\n\t'rest_authentication_errors',\r\n\tstatic function ( $result ) {\r\n\t\tif ( is_wp_error( $result ) ) {\r\n\t\t\treturn $result;\r\n\t\t}\r\n\r\n\t\tif ( ! is_user_logged_in() ) {\r\n\t\t\treturn new \\WP_Error(\r\n\t\t\t\t'rest_not_logged_in',\r\n\t\t\t\t__( 'This content is restricted to logged-in users.' ),\r\n\t\t\t\tarray( 'status' => 401 )\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\treturn $result;\r\n\t}\r\n);\r\n\r\n\/\/ Don't allow indexing.\r\nadd_action( 'pre_option_blog_public', '__return_zero' );\r\n","note":"Make your site private just for logged-in users.","categories":["login"],"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":33959,"title":"Author Bio After Post","code":"global $post;\r\n$author_id = $post->post_author;\r\n\r\n\/\/ Get author's display name and biographical info\r\n$author_name = get_the_author_meta( 'display_name', $author_id );\r\n$author_bio = get_the_author_meta( 'description', $author_id );\r\n\r\n\/\/ Get author's avatar\r\n$author_avatar = get_avatar( $author_id, 96 );\r\n\r\n\/\/ Only display if author bio is not empty\r\nif ( ! empty( $author_bio ) ) {\r\n\t$bio_content = '<div class=\"author-bio\">';\r\n\t$bio_content .= '<div class=\"author-avatar\">' . $author_avatar . '<\/div>';\r\n\t$bio_content .= '<div class=\"author-info\">';\r\n\t$bio_content .= '<h4>' . esc_html( $author_name ) . '<\/h4>';\r\n\t$bio_content .= '<p>' . wp_kses_post( $author_bio ) . '<\/p>';\r\n\t$bio_content .= '<\/div>';\r\n\t$bio_content .= '<\/div>';\r\n\r\n\t\/\/ Output bio.\r\n\techo $bio_content;\r\n}","note":"Display the author bio (if any) after the post content.","categories":["widgets"],"code_type":"php","needs_auth":false},{"library_id":27164,"title":"Auto-Collapse Long Comments","code":"\r\nadd_filter( 'comment_text', function( $comment_content ) {\r\n\t$max_length = 100; \/\/ Set the maximum length of the comment to display without collapsing\r\n\tif ( strlen( $comment_content ) > $max_length ) {\r\n\t\t$short_content = substr( $comment_content, 0, $max_length ) . '...';\r\n\t\t$full_content = esc_html( $comment_content );\r\n\r\n\t\t$comment_content = '<div class=\"collapsed-comment\">' . esc_html( $short_content ) . ' <a href=\"#\" class=\"read-more\">Read more<\/a><\/div>';\r\n\t\t$comment_content .= '<div class=\"full-comment\" style=\"display:none;\">' . $full_content . ' <a href=\"#\" class=\"read-less\">Read less<\/a><\/div>';\r\n\t}\r\n\treturn $comment_content;\r\n} );\r\n\r\nadd_action('wp_footer', function() {\r\n\techo '<script type=\"text\/javascript\">\r\n document.addEventListener(\"DOMContentLoaded\", function() {\r\n var readMoreLinks = document.querySelectorAll(\".read-more\");\r\n var readLessLinks = document.querySelectorAll(\".read-less\");\r\n\r\n readMoreLinks.forEach(function(link) {\r\n link.addEventListener(\"click\", function(e) {\r\n e.preventDefault();\r\n link.parentElement.style.display = \"none\";\r\n link.parentElement.nextElementSibling.style.display = \"block\";\r\n });\r\n });\r\n\r\n readLessLinks.forEach(function(link) {\r\n link.addEventListener(\"click\", function(e) {\r\n e.preventDefault();\r\n link.parentElement.style.display = \"none\";\r\n link.parentElement.previousElementSibling.style.display = \"block\";\r\n });\r\n });\r\n });\r\n <\/script>';\r\n} );","note":"Add a \"Read More\" button for long comments for better layouts.","categories":["comments"],"code_type":"php","needs_auth":false},{"library_id":28375,"title":"Auto-logout inactive users","code":"<script type=\"text\/javascript\">\r\n\tvar logoutUrl = '<?php echo htmlspecialchars_decode( wp_logout_url() ); ?>';\r\n\tvar timeout;\r\n\r\n\tdocument.onload = resetTimeout;\r\n\tdocument.onmousemove = resetTimeout;\r\n\tdocument.onkeypress = resetTimeout;\r\n\r\n\tfunction resetTimeout() {\r\n\t\tclearTimeout( timeout );\r\n\t\ttimeout = setTimeout( function () {\r\n\t\t\twindow.location.href = logoutUrl;\r\n\t\t}, 600000 ); \/\/ 10 minutes\r\n\t}\r\n<\/script>","note":"Automatically logout users after 10 minutes.","categories":["login"],"code_type":"universal","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":21351,"title":"Back to Top Button","code":"<style>\r\n\t#back-to-top {\r\n\t\tdisplay: none;\r\n\t\tposition: fixed;\r\n\t\tbottom: 20px;\r\n\t\tright: 20px;\r\n\t\tbackground-color: rgba(0, 0, 0, 0.7);\r\n\t\tcolor: #fff;\r\n\t\twidth: 40px;\r\n\t\theight: 40px;\r\n\t\ttext-align: center;\r\n\t\tborder-radius: 5px;\r\n\t\tline-height: 40px;\r\n\t\tcursor: pointer;\r\n\t\ttransition: display 0.3s ease, background-color 300ms ease;\r\n\t\tborder: none;\r\n\t\tpadding: 0;\r\n\t}\r\n\r\n\t#back-to-top:hover {\r\n\t\tbackground-color: rgba(0, 0, 0, 1);\r\n\t}\r\n<\/style>\r\n\r\n<button id=\"back-to-top\">\u25b2<\/button>\r\n\r\n<script>\r\n\tvar backToTop = document.getElementById( 'back-to-top' );\r\n\r\n\twindow.addEventListener( 'scroll', function () {\r\n\t\tif ( document.body.scrollTop > 20 || document.documentElement.scrollTop > 20 ) {\r\n\t\t\tbackToTop.style.display = 'block';\r\n\t\t} else {\r\n\t\t\tbackToTop.style.display = 'none';\r\n\t\t}\r\n\t} );\r\n\r\n\tbackToTop.addEventListener( 'click', function ( e ) {\r\n\t\te.preventDefault();\r\n\t\twindow.scrollTo( {top: 0, behavior: 'smooth'} );\r\n\t} );\r\n<\/script>","note":"Add a simple button to scroll back to top on the frontend.","categories":["archive"],"code_type":"html","needs_auth":false},{"library_id":13588,"title":"Block WP-Admin Area from Non-Administrators","code":"add_action( 'admin_init', function() {\r\n\tif ( ! current_user_can( 'administrator' ) ) {\r\n wp_redirect( home_url() );\r\n exit;\r\n\t}\r\n} );\r\n","note":"Prevent users who are not administrators from accessing the wp-admin area.","categories":["admin"],"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\tif ( ! isset( $my_account->title ) ) {\r\n\t\treturn;\r\n\t}\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', 9999 );\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":32246,"title":"Change Editor Default Image Size","code":"add_filter( 'block_editor_settings_all', function ( $settings, $context ) {\r\n\t\/\/ The default image size when added in the block editor.\r\n\t$settings['imageDefaultSize'] = 'full';\r\n\r\n\treturn $settings;\r\n}, 10, 2 );\r\n","note":"Set the default image size to full instead of large in the block editor.","categories":["attachments"],"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":33967,"title":"Copy Button for Code Blocks","code":"<script type=\"text\/javascript\">\r\n\tdocument.addEventListener( 'DOMContentLoaded', function () {\r\n\t\tdocument.querySelectorAll( 'pre > code' ).forEach( function ( codeBlock ) {\r\n\t\t\tvar copyButton = document.createElement( 'button' );\r\n\t\t\tcopyButton.textContent = 'Copy';\r\n\t\t\tcopyButton.classList.add( 'copy-button' );\r\n\t\t\tcodeBlock.parentNode.insertBefore( copyButton, codeBlock );\r\n\r\n\t\t\tcopyButton.addEventListener( 'click', function () {\r\n\t\t\t\tvar code = codeBlock.textContent;\r\n\t\t\t\tnavigator.clipboard.writeText( code ).then( function () {\r\n\t\t\t\t\tcopyButton.textContent = 'Copied!';\r\n\t\t\t\t\tsetTimeout( function () {\r\n\t\t\t\t\t\tcopyButton.textContent = 'Copy';\r\n\t\t\t\t\t}, 2000 );\r\n\t\t\t\t}, function ( err ) {\r\n\t\t\t\t\tconsole.error( 'Could not copy text: ', err );\r\n\t\t\t\t\tcopyButton.textContent = 'Error';\r\n\t\t\t\t\tsetTimeout( function () {\r\n\t\t\t\t\t\tcopyButton.textContent = 'Copy';\r\n\t\t\t\t\t}, 2000 );\r\n\t\t\t\t} );\r\n\t\t\t} );\r\n\t\t} );\r\n\t} );\r\n<\/script>\r\n<style>\r\n\t.copy-button {\r\n\t\tbackground-color: #f0f0f0;\r\n\t\tborder: 1px solid #ccc;\r\n\t\tborder-radius: 4px;\r\n\t\tpadding: 5px 10px;\r\n\t\tcursor: pointer;\r\n\t\tfont-size: 0.8em;\r\n\t\tposition: absolute;\r\n\t\ttop: 0.5em;\r\n\t\tright: 0.5em;\r\n\t}\r\n\r\n\tpre {\r\n\t\tposition: relative;\r\n\t}\r\n<\/style>","note":"Add a button to easily copy to clipboard for code blocks.","categories":["widgets"],"code_type":"html","needs_auth":false},{"library_id":28373,"title":"Custom Default Avatar","code":"\/**\r\n * IMPORTANT: After activating this snippet you have to change the default avatar option in Settings \u00bb Discussion to \"Custom Avatar\" as defined below.\r\n *\/\r\n\r\nadd_filter( 'avatar_defaults', function( $avatar_defaults ) {\r\n $new_avatar_url = 'https:\/\/wpcode.com\/wp-content\/uploads\/2024\/09\/wpcode-avatar.png'; \/\/ Replace this with your default avatar image URL.\r\n $avatar_defaults[$new_avatar_url] = 'Custom Avatar';\r\n return $avatar_defaults;\r\n});","note":"Use a custom image for the default avatar.","categories":["comments"],"code_type":"php","needs_auth":false},{"library_id":29706,"title":"Custom Logo Per Page","code":"add_action('add_meta_boxes', function() {\r\n add_meta_box(\r\n 'custom-logo-metabox',\r\n 'Custom Logo',\r\n function($post) {\r\n \/\/ Add a nonce field so we can check for it later\r\n wp_nonce_field('custom_logo_meta_box', 'custom_logo_meta_box_nonce');\r\n \r\n \/\/ Retrieve the existing value from the database\r\n $custom_logo_id = get_post_meta($post->ID, '_custom_logo_id', true);\r\n $custom_logo_url = $custom_logo_id ? wp_get_attachment_image_url($custom_logo_id, 'thumbnail') : '';\r\n\r\n \/\/ Output the form fields\r\n echo '<div style=\"margin-bottom: 10px;\">';\r\n echo '<img id=\"custom-logo-preview\" src=\"' . esc_url($custom_logo_url) . '\" style=\"max-width: 100%; display: ' . ($custom_logo_url ? 'block' : 'none') . ';\" \/>';\r\n echo '<input type=\"hidden\" id=\"custom_logo_id\" name=\"custom_logo_id\" value=\"' . esc_attr($custom_logo_id) . '\" \/>';\r\n echo '<button type=\"button\" class=\"button\" id=\"upload_custom_logo_button\">Upload Logo<\/button>';\r\n echo '<button type=\"button\" class=\"button\" id=\"remove_custom_logo_button\" style=\"display: ' . ($custom_logo_url ? 'inline-block' : 'none') . ';\">Remove Logo<\/button>'; \r\n echo '<\/div>';\r\n\r\n \/\/ Add a script to handle the media uploader\r\n ?>\r\n <script>\r\n jQuery(document).ready(function($){\r\n var file_frame;\r\n $('#upload_custom_logo_button').on('click', function(event){\r\n event.preventDefault();\r\n if (file_frame) {\r\n file_frame.open();\r\n return;\r\n }\r\n\r\n file_frame = wp.media.frames.file_frame = wp.media({\r\n title: 'Select or Upload a Custom Logo',\r\n button: {\r\n text: 'Use this logo',\r\n },\r\n multiple: false\r\n });\r\n\r\n file_frame.on('select', function() {\r\n var attachment = file_frame.state().get('selection').first().toJSON();\r\n $('#custom_logo_id').val(attachment.id);\r\n $('#custom-logo-preview').attr('src', attachment.sizes.thumbnail.url).show();\r\n $('#remove_custom_logo_button').show();\r\n });\r\n\r\n file_frame.open();\r\n });\r\n\r\n $('#remove_custom_logo_button').on('click', function() {\r\n $('#custom_logo_id').val('');\r\n $('#custom-logo-preview').hide();\r\n $(this).hide();\r\n });\r\n });\r\n <\/script>\r\n <?php\r\n },\r\n 'page',\r\n 'side'\r\n );\r\n});\r\n\r\nadd_action('save_post', function($post_id) {\r\n \/\/ Check if our nonce is set.\r\n if (!isset($_POST['custom_logo_meta_box_nonce'])) {\r\n return;\r\n }\r\n\r\n \/\/ Verify that the nonce is valid.\r\n if (!wp_verify_nonce($_POST['custom_logo_meta_box_nonce'], 'custom_logo_meta_box')) {\r\n return;\r\n }\r\n\r\n \/\/ Check this is not an autosave.\r\n if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {\r\n return;\r\n }\r\n\r\n \/\/ Check the user's permissions.\r\n if (isset($_POST['post_type']) && 'page' == $_POST['post_type']) {\r\n if (!current_user_can('edit_page', $post_id)) {\r\n return;\r\n }\r\n } else {\r\n if (!current_user_can('edit_post', $post_id)) {\r\n return;\r\n }\r\n }\r\n\r\n \/\/ Sanitize the user input.\r\n if (isset($_POST['custom_logo_id'])) {\r\n $custom_logo_id = absint($_POST['custom_logo_id']);\r\n update_post_meta($post_id, '_custom_logo_id', $custom_logo_id);\r\n }\r\n});\r\n\r\nadd_filter('get_custom_logo', function($html) {\r\n if (is_page()) {\r\n $custom_logo_id = get_post_meta(get_the_ID(), '_custom_logo_id', true);\r\n if ($custom_logo_id) {\r\n $custom_logo_url = wp_get_attachment_image_url($custom_logo_id, 'full');\r\n if ($custom_logo_url) {\r\n \/\/ Assuming the logo is wrapped in an image element\r\n $html = '<img src=\"' . esc_url($custom_logo_url) . '\" alt=\"' . get_bloginfo('name') . '\">';\r\n }\r\n }\r\n }\r\n return $html;\r\n});\r\n\r\nadd_filter('get_site_icon_url', function($url, $size, $blog_id) {\r\n if (is_page()) {\r\n \/\/ Get the current page's ID\r\n $post_id = get_the_ID();\r\n\r\n \/\/ Retrieve the custom logo URL from post meta\r\n $custom_logo_id = get_post_meta($post_id, '_custom_logo_id', true);\r\n if ($custom_logo_id) {\r\n $custom_logo_url = wp_get_attachment_image_url($custom_logo_id, array($size, $size));\r\n if ($custom_logo_url) {\r\n return $custom_logo_url;\r\n }\r\n }\r\n }\r\n return $url;\r\n}, 10, 3);","note":"Add a way to choose a custom logo for each page.","categories":["attachments"],"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":29714,"title":"Default Featured Image","code":"\/\/ Go to Settings > Media after activating this snippet to set the default featured image.\r\nadd_action( 'admin_init', function() {\r\n\tregister_setting( 'media', 'default_featured_image', 'absint' );\r\n\r\n\tadd_settings_field(\r\n\t\t'default_featured_image',\r\n\t\t__( 'Default Featured Image', 'wpcode-snippet' ),\r\n\t\tfunction() {\r\n\t\t\twp_enqueue_media();\r\n\t\t\t$image_id = get_option( 'default_featured_image', 0 );\r\n\t\t\t$image_url = $image_id ? wp_get_attachment_url( $image_id ) : '';\r\n\t\t\t?>\r\n\t\t\t<div>\r\n\t\t\t\t<img id=\"default-featured-image-preview\" src=\"<?php echo esc_url( $image_url ); ?>\" style=\"max-width: 150px; display: <?php echo $image_url ? 'block' : 'none'; ?>; margin-bottom: 10px;\"\/>\r\n\t\t\t\t<input type=\"hidden\" id=\"default_featured_image\" name=\"default_featured_image\" value=\"<?php echo esc_attr( $image_id ); ?>\"\/>\r\n\t\t\t\t<button type=\"button\" class=\"button\" id=\"upload-default-featured-image\"><?php esc_html_e( 'Choose Image', 'wpcode-snippet' ); ?><\/button>\r\n\t\t\t\t<button type=\"button\" class=\"button\" id=\"remove-default-featured-image\"><?php esc_html_e( 'Remove Image', 'wpcode-snippet' ); ?><\/button>\r\n\t\t\t<\/div>\r\n\t\t\t<script>\r\n\t\t\t\tjQuery( document ).ready( function ( $ ) {\r\n\t\t\t\t\tvar removeButton = $( '#remove-default-featured-image' );\r\n\t\t\t\t\tvar frame;\r\n\t\t\t\t\t$( '#upload-default-featured-image' ).on( 'click', function ( event ) {\r\n\t\t\t\t\t\tevent.preventDefault();\r\n\t\t\t\t\t\tif ( frame ) {\r\n\t\t\t\t\t\t\tframe.open();\r\n\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tframe = wp.media( {\r\n\t\t\t\t\t\t\ttitle: '<?php echo esc_js( __( 'Select Default Featured Image', 'wpcode-snippet' ) ); ?>',\r\n\t\t\t\t\t\t\tbutton: {\r\n\t\t\t\t\t\t\t\ttext: '<?php echo esc_js( __( 'Use this image', 'wpcode-snippet' ) ); ?>'\r\n\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\tmultiple: false\r\n\t\t\t\t\t\t} );\r\n\t\t\t\t\t\tframe.on( 'select', function () {\r\n\t\t\t\t\t\t\tvar attachment = frame.state().get( 'selection' ).first().toJSON();\r\n\t\t\t\t\t\t\t$( '#default_featured_image' ).val( attachment.id );\r\n\t\t\t\t\t\t\t$( '#default-featured-image-preview' ).attr( 'src', attachment.url ).show();\r\n\t\t\t\t\t\t\tremoveButton.show();\r\n\t\t\t\t\t\t} );\r\n\t\t\t\t\t\tframe.open();\r\n\t\t\t\t\t} );\r\n\r\n\t\t\t\t\t$( '#remove-default-featured-image' ).on( 'click', function () {\r\n\t\t\t\t\t\t$( '#default_featured_image' ).val( '' );\r\n\t\t\t\t\t\t$( '#default-featured-image-preview' ).hide();\r\n\t\t\t\t\t\tremoveButton.hide();\r\n\t\t\t\t\t} );\r\n\r\n\t\t\t\t\tif ( $( '#default_featured_image' ).val() === '0' ) {\r\n\t\t\t\t\t\tremoveButton.hide();\r\n\t\t\t\t\t}\r\n\t\t\t\t} );\r\n\t\t\t<\/script>\r\n\t\t\t<?php\r\n\t\t},\r\n\t\t'media',\r\n\t\t'default',\r\n\t\tarray( 'label_for' => 'default_featured_image' )\r\n\t);\r\n});\r\n\r\nadd_filter( 'post_thumbnail_html', function( $html, $post_id, $post_thumbnail_id, $size, $attr ) {\r\n\tif ( ! $html ) {\r\n\t\t$default_image_id = get_option( 'default_featured_image' );\r\n\t\tif ( $default_image_id ) {\r\n\t\t\t$image_url = wp_get_attachment_image_src( $default_image_id, $size );\r\n\t\t\tif ( $image_url ) {\r\n\t\t\t\t$html = '<img src=\"' . esc_url( $image_url[0] ) . '\" class=\"attachment-' . esc_attr( $size ) . ' wp-post-image\" alt=\"' . esc_attr( get_the_title( $post_id ) ) . '\" \/>';\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn $html;\r\n}, 10, 5 );","note":"Add a setting in Media for a default featured image for all posts.","categories":["attachments"],"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":25497,"title":"Disable All Updates","code":"\r\nadd_filter( 'site_transient_update_plugins', '__return_empty_array' );\r\nadd_filter( 'transient_update_plugins', '__return_empty_array' );\r\nadd_filter( 'site_transient_update_themes', '__return_empty_array' );\r\nadd_filter( 'transient_update_themes', '__return_empty_array' );\r\n\r\n\/\/ Disable core wp updates.\r\nadd_filter( 'pre_site_transient_update_core', function ( $object = null ) {\r\n\tglobal $wp_version;\r\n\r\n\t\/\/ Return an empty object to prevent extra checks.\r\n\treturn (object) array(\r\n\t\t'last_checked' => time(),\r\n\t\t'updates' => array(),\r\n\t\t'version_checked' => $wp_version,\r\n\t);\r\n} );\r\n\r\nadd_action( 'init', function () {\r\n\tremove_action( 'init', 'wp_version_check' );\r\n\tadd_filter( 'pre_option_update_core', '__return_null' );\r\n\tremove_all_filters( 'plugins_api' );\r\n} );\r\n\r\n\/\/ Disable even other external updates related to core.\r\nadd_filter( 'auto_update_translation', '__return_false' );\r\nadd_filter( 'automatic_updater_disabled', '__return_true' );\r\nadd_filter( 'allow_minor_auto_core_updates', '__return_false' );\r\nadd_filter( 'allow_major_auto_core_updates', '__return_false' );\r\nadd_filter( 'allow_dev_auto_core_updates', '__return_false' );\r\nadd_filter( 'auto_update_core', '__return_false' );\r\nadd_filter( 'wp_auto_update_core', '__return_false' );\r\nadd_filter( 'auto_update_plugin', '__return_false' );\r\nadd_filter( 'auto_update_theme', '__return_false' );\r\nadd_filter( 'auto_core_update_send_email', '__return_false' );\r\nadd_filter( 'automatic_updates_send_debug_email ', '__return_false' );\r\nadd_filter( 'send_core_update_notification_email', '__return_false' );\r\nadd_filter( 'automatic_updates_is_vcs_checkout', '__return_true' );\r\n\r\nadd_filter( 'pre_site_transient_update_plugins', function () {\r\n\tglobal $wp_version;\r\n\t\/\/ Get all registered plugins.\r\n\t$plugins = get_transient( 'wpcode_prevent_updates_plugins' );\r\n\tif ( false === $plugins ) {\r\n\t\tif ( ! function_exists( 'get_plugins' ) ) {\r\n\t\t\trequire_once ABSPATH . 'wp-admin\/includes\/plugin.php';\r\n\t\t}\r\n\t\t$plugins = array();\r\n\r\n\t\tforeach ( get_plugins() as $file => $plugin ) {\r\n\t\t\t$plugins[ $file ] = $plugin['Version'];\r\n\t\t}\r\n\r\n\t\tset_transient( 'wpcode_prevent_updates', $plugins, DAY_IN_SECONDS );\r\n\t}\r\n\r\n\t\/\/ Return an empty object to prevent extra checks.\r\n\treturn (object) array(\r\n\t\t'last_checked' => time(),\r\n\t\t'updates' => array(),\r\n\t\t'version_checked' => $wp_version,\r\n\t\t'checked' => $plugins,\r\n\t);\r\n} );\r\n\r\nadd_filter( 'pre_site_transient_update_themes', function () {\r\n\tglobal $wp_version;\r\n\t\/\/ Get all registered themes.\r\n\t$themes = get_transient( 'wpcode_prevent_updates_themes' );\r\n\tif ( false === $themes ) {\r\n\t\t$themes = array();\r\n\t\tforeach ( wp_get_themes() as $theme ) {\r\n\t\t\t$themes[ $theme->get_stylesheet() ] = $theme->get( 'Version' );\r\n\t\t}\r\n\r\n\t\tset_transient( 'wpcode_prevent_updates_themes', $themes, DAY_IN_SECONDS );\r\n\t}\r\n\r\n\t\/\/ Return an empty object to prevent extra checks.\r\n\treturn (object) array(\r\n\t\t'last_checked' => time(),\r\n\t\t'updates' => array(),\r\n\t\t'version_checked' => $wp_version,\r\n\t\t'checked' => $themes,\r\n\t);\r\n} );\r\n\r\nadd_action( 'admin_init', function () {\r\n\t\/\/ Remove updates page.\r\n\tremove_submenu_page( 'index.php', 'update-core.php' );\r\n\r\n\t\/\/ Disable plugin API checks.\r\n\tremove_all_filters( 'plugins_api' );\r\n\r\n\t\/\/ Disable theme checks.\r\n\tremove_action( 'load-update-core.php', 'wp_update_themes' );\r\n\tremove_action( 'load-themes.php', 'wp_update_themes' );\r\n\tremove_action( 'load-update.php', 'wp_update_themes' );\r\n\tremove_action( 'wp_update_themes', 'wp_update_themes' );\r\n\tremove_action( 'admin_init', '_maybe_update_themes' );\r\n\twp_clear_scheduled_hook( 'wp_update_themes' );\r\n\r\n\t\/\/ Disable plugin checks.\r\n\tremove_action( 'load-update-core.php', 'wp_update_plugins' );\r\n\tremove_action( 'load-plugins.php', 'wp_update_plugins' );\r\n\tremove_action( 'load-update.php', 'wp_update_plugins' );\r\n\tremove_action( 'admin_init', '_maybe_update_plugins' );\r\n\tremove_action( 'wp_update_plugins', 'wp_update_plugins' );\r\n\twp_clear_scheduled_hook( 'wp_update_plugins' );\r\n\r\n\t\/\/ Disable any other update\/cron checks.\r\n\tremove_action( 'wp_version_check', 'wp_version_check' );\r\n\tremove_action( 'admin_init', '_maybe_update_core' );\r\n\tremove_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' );\r\n\tremove_action( 'admin_init', 'wp_maybe_auto_update' );\r\n\tremove_action( 'admin_init', 'wp_auto_update_core' );\r\n\twp_clear_scheduled_hook( 'wp_version_check' );\r\n\twp_clear_scheduled_hook( 'wp_maybe_auto_update' );\r\n\r\n\t\/\/ Hide nag messages.\r\n\tremove_action( 'admin_notices', 'update_nag', 3 );\r\n\tremove_action( 'network_admin_notices', 'update_nag', 3 );\r\n\tremove_action( 'admin_notices', 'maintenance_nag' );\r\n\tremove_action( 'network_admin_notices', 'maintenance_nag' );\r\n} );","note":"Hide all updates for WordPress Core, Plugins and Themes.","categories":["disable"],"code_type":"php","needs_auth":false},{"library_id":19984,"title":"Disable Application Passwords","code":"add_filter('wp_is_application_passwords_available', '__return_false');","note":"Disable Application Passwords feature that was added in WP 5.6.","categories":["admin","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":18702,"title":"Disable Author Archives","code":"\/\/ Return a 404 page for author pages if accessed directly.\r\nadd_action( 'template_redirect', function () {\r\n\tif ( is_author() ) {\r\n\t\tglobal $wp_query;\r\n\t\t$wp_query->set_404();\r\n\t\tstatus_header( 404 );\r\n\t\tnocache_headers();\r\n\t}\r\n} );\r\n\r\n\/\/ Remove the author links.\r\nadd_filter( 'author_link', '__return_empty_string', 1000 );\r\nadd_filter( 'the_author_posts_link', 'get_the_author', 1000, 0 );\r\n\r\n\/\/ Remove the author pages from the WP 5.5+ sitemap.\r\nadd_filter( 'wp_sitemaps_add_provider', function ( $provider, $name ) {\r\n\tif ( 'users' === $name ) {\r\n\t\treturn false;\r\n\t}\r\n\r\n\treturn $provider;\r\n}, 10, 2 );\r\n\r\n\/\/ Remove admin links in the list of users.\r\nadd_filter( 'user_row_actions', function ( $actions, $user ) {\r\n\tunset( $actions['view'] );\r\n\tunset( $actions['posts'] );\r\n\r\n\treturn $actions;\r\n}, 10, 2 );","note":"Completely hide author archives and prevent direct access by returning a 404 page.","categories":["archive","disable"],"code_type":"php","needs_auth":false},{"library_id":24305,"title":"Disable Auto-Scaling Oversized Images","code":"add_filter( 'big_image_size_threshold', '__return_false' );","note":"Prevent WordPress from scaling large images added in v5.3.","categories":["attachments","disable"],"code_type":"php","needs_auth":false},{"library_id":13592,"title":"Disable Automatic Trash Emptying","code":"add_action( 'init', function() {\r\n remove_action( 'wp_scheduled_delete', 'wp_scheduled_delete' );\r\n} );","note":"Prevent WordPress from automatically deleting trashed posts after 30 days.","categories":["admin","disable"],"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":15148,"title":"Disable Block Directory","code":"remove_action('enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets');","note":"Prevent block directory results from being shown when searching for blocks in the editor.","categories":["admin","disable"],"code_type":"php","needs_auth":false},{"library_id":24309,"title":"Disable Categories and Tags","code":"add_action('init', function() {\r\n unregister_taxonomy_for_object_type('category', 'post');\r\n unregister_taxonomy_for_object_type('post_tag', 'post');\r\n});","note":"Disable the default taxonomies for Posts (Categories, Tags).","categories":["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\tif ( isset( $fields['cookies'] ) ) {\r\n\t\t\/\/ Remove the website mention from the cookies checkbox label.\r\n\t\t$fields['cookies'] = str_replace('name, email, and website', 'name and email', $fields['cookies']);\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":19986,"title":"Disable Comment URL Linking","code":"remove_filter( 'comment_text', 'make_clickable', 9 );","note":"Prevent automatically formatting URLs in comments as links.","categories":["comments"],"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":15146,"title":"Disable Full Site Editing (FSE)","code":"add_action( 'admin_menu', function() {\r\n\tremove_submenu_page('themes.php', 'site-editor.php');\r\n});\r\nadd_action('admin_bar_menu', function($wp_admin_bar) {\r\n\t$wp_admin_bar->remove_node('site-editor');\r\n}, 250);\r\nadd_action('admin_init', function() {\r\n\tglobal $pagenow;\r\n\tif ('site-editor.php' === $pagenow) {\r\n\t\twp_safe_redirect(admin_url()); \r\n\t\texit;\r\n\t}\r\n});","note":"Prevent any user from making changes to the site using the Full Site Editor.","categories":["admin","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":24313,"title":"Disable Gravatar Avatars","code":"add_filter( 'get_avatar', function( $avatar, $id_or_email, $size, $default, $alt ) {\r\n return ''; \/\/ Return an empty string to disable the gravatar\r\n}, 10, 5 );","note":"Prevent WordPress from loading gravatar avatars for users.","categories":["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":32244,"title":"Disable Inspector Tabs","code":"add_filter( 'block_editor_settings_all', function ( $settings ) {\r\n\tif ( ! isset( $settings['blockInspectorTabs'] ) ) {\r\n\t\t$settings['blockInspectorTabs'] = array();\r\n\t}\r\n\r\n\t$settings['blockInspectorTabs'] = array_merge(\r\n\t\t$settings[ 'blockInspectorTabs' ],\r\n\t\tarray( \r\n\t\t\t'default' => false, \/\/ Disables for all blocks.\r\n\t\t),\r\n\t);\r\n\r\n\treturn $settings;\r\n} );","note":"Revert having a separate tab for block styles.","categories":["admin","disable"],"code_type":"php","needs_auth":false},{"library_id":17253,"title":"Disable jQuery Migrate","code":"add_action( 'wp_default_scripts', function ( $scripts ) {\r\n\tif ( ! is_admin() && isset( $scripts->registered['jquery'] ) ) {\r\n\t\t$script = $scripts->registered['jquery'];\r\n\t\tif ( ! empty( $script->deps ) ) {\r\n\t\t\t$script->deps = array_diff( $script->deps, array( 'jquery-migrate' ) );\r\n\t\t}\r\n\t}\r\n}, 150 );","note":"Prevent loading the jQuery Migrate script in the frontend.","categories":["disable"],"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":25489,"title":"Disable Legacy CSS","code":"add_filter( 'show_recent_comments_widget_style', '__return_false' );\r\nadd_filter( 'use_default_gallery_style', '__return_false' );","note":"Stop loading styles for recent comments and classic gallery shortcode.","categories":["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":32242,"title":"Disable Openverse","code":"add_filter( 'block_editor_settings_all', function( $settings, $context ) {\r\n\t$settings['enableOpenverseMediaCategory'] = false;\r\n\treturn $settings;\r\n}, 10, 2 );","note":"Disable the Openverse integration for the media inserter.","categories":["admin","disable"],"code_type":"php","needs_auth":false},{"library_id":18699,"title":"Disable Pattern Directory","code":"add_action( 'after_setup_theme', function() {\r\n\t remove_theme_support( 'core-block-patterns' );\r\n});","note":"Prevent patterns from being shown in the Gutenberg editor block inserter.","categories":["admin","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":24311,"title":"Disable Post Formats","code":"add_action( 'after_setup_theme', function() {\r\n remove_theme_support( 'post-formats' );\r\n}, 11 );","note":"Disable the Post Formats feature for all posts.","categories":["disable"],"code_type":"php","needs_auth":false},{"library_id":15144,"title":"Disable Posts in Admin","code":"add_action( 'admin_bar_menu', function ( $wp_admin_bar ) {\r\n\t$wp_admin_bar->remove_node( 'new-post' );\r\n}, 100 );\r\n\r\nadd_action( 'admin_menu', function () {\r\n\tremove_menu_page( 'edit.php' );\r\n} );","note":"Hide the Posts menu from the admin if you don't need the default Posts post...","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":13595,"title":"Disable Site Admin Email Verification","code":"add_filter( 'admin_email_check_interval', '__return_false' );\r\n","note":"Stop WordPress from asking you to confirm the administrator email address when logging in.","categories":["admin"],"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":18697,"title":"Disable Specific Blocks","code":"add_filter( 'allowed_block_types_all', function ( $allowed_block_types, $block_editor_context ) {\r\n\r\n\t\/\/ List here the blocks you want to disallow. https:\/\/developer.wordpress.org\/block-editor\/reference-guides\/core-blocks\/\r\n\t$disallowed_blocks = array(\r\n\t\t'core\/navigation',\r\n\t\t'core\/query',\r\n\t);\r\n\r\n\tif ( ! is_array( $allowed_block_types ) || empty( $allowed_block_types ) ) {\r\n\t\t$registered_blocks = WP_Block_Type_Registry::get_instance()->get_all_registered();\r\n\t\t$allowed_block_types = array_keys( $registered_blocks );\r\n\t}\r\n\r\n\t$filtered_blocks = array();\r\n\tforeach ( $allowed_block_types as $block ) {\r\n\t\tif ( ! in_array( $block, $disallowed_blocks, true ) ) {\r\n\t\t\t$filtered_blocks[] = $block;\r\n\t\t}\r\n\t}\r\n\r\n\treturn $filtered_blocks;\r\n}, 10, 2 );","note":"Prevent certain blocks from being used in the Gutenberg Editor.","categories":["admin","disable"],"code_type":"php","needs_auth":false},{"library_id":32240,"title":"Disable Template Editor","code":"add_action( 'current_screen', function () {\r\n $screen = get_current_screen();\r\n\r\n\t\/\/ Add other custom post types here as needed.\r\n if ( in_array( $screen->id, array( 'post', 'page' ) ) ) {\r\n remove_theme_support( 'block-templates' );\r\n }\r\n} );","note":"Disable access to modify or create templates from the Post Editor.","categories":["admin","disable"],"code_type":"php","needs_auth":false},{"library_id":15142,"title":"Disable the Excerpt in RSS Feeds","code":"\/\/ Make sure we display the excerpt in the feed.\r\nadd_filter( 'pre_option_rss_use_excerpt', '__return_true' );\r\n\/\/ Remove the excerpt content for feeds.\r\nadd_filter( 'the_excerpt_rss', '__return_empty_string' );","note":"Hide the excerpt or content from your RSS feeds.","categories":["rss-feeds"],"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":21345,"title":"Disable Thumbnail Image Sizes","code":"add_filter( 'intermediate_image_sizes_advanced', function( $sizes ) {\r\n\t\/\/ Disable specific thumbnail sizes, uncomment the ones you want to disable.\r\n\r\n\t\/\/ unset( $sizes['thumbnail'] ); \/\/ 150px x 150px\r\n\t\/\/ unset( $sizes['medium'] ); \/\/ 300px x 300px\r\n\t\/\/ unset( $sizes['medium_large'] ); \/\/ 768px x 0px\r\n\t\/\/ unset( $sizes['large'] ); \/\/ 1024px x 1024px\r\n\t\/\/ unset( $sizes['1536x1536'] ); \/\/ 1536px x 1536px\r\n\t\/\/ unset( $sizes['2048x2048'] ); \/\/ 2048px x 2048px\r\n\t\r\n\treturn $sizes;\r\n} );","note":"Prevent WordPress from generating specific thumbnail sizes.","categories":["attachments","disable"],"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":21338,"title":"Disable WordPress 6.5 Font Library","code":"add_filter( 'block_editor_settings_all', function( $editor_settings ) {\r\n\t$editor_settings['fontLibraryEnabled'] = false;\r\n \treturn $editor_settings; \r\n} );\r\n\r\n\/\/ Disable the REST API for the font library.\r\nadd_filter( 'register_post_type_args', function( $arg, $post_type ) {\r\n\tif ( 'wp_font_family' === $post_type || 'wp_font_face' === $post_type ) {\r\n\t\t$arg['show_in_rest'] = false;\r\n\t}\r\n\r\n\treturn $arg;\r\n}, 10, 2 );\r\n\r\nadd_filter( 'rest_endpoints', function( $endpoints ) {\r\n\tforeach ( $endpoints as $route => $endpoint ){\r\n\t\tif ( str_starts_with( $route, '\/wp\/v2\/font-collections' ) ) {\r\n\t\t\tunset( $endpoints[ $route ] );\r\n\t\t}\r\n\t}\r\n\r\n\treturn $endpoints;\r\n} );","note":"Deactivate the font library feature added in WordPress 6.5.","categories":["admin"],"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":28370,"title":"Display Random Posts","code":"$number_of_posts = 5; \/\/ Change this to the number of random posts you want to display.\r\n$title = 'You might also like:'; \/\/ This is the title that will be displayed above the list of posts.\r\n$current_post_id = get_the_ID();\r\n$args = array(\r\n\t'post_type' => 'post',\r\n\t'orderby' => 'rand',\r\n\t'posts_per_page' => $number_of_posts,\r\n\t'post__not_in' => array( $current_post_id ),\r\n);\r\n$random_posts = new WP_Query( $args );\r\nif ( $random_posts->have_posts() ) {\r\n\techo '<h3>' . esc_html( $title ) . '<\/h3>';\r\n\techo '<ul>';\r\n\twhile ( $random_posts->have_posts() ) {\r\n\t\t$random_posts->the_post();\r\n\t\techo '<li><a href=\"' . esc_url( get_permalink() ) . '\">' . esc_html( get_the_title() ) . '<\/a><\/li>';\r\n\t}\r\n\techo '<\/ul>';\r\n}\r\nwp_reset_postdata();","note":"Show random posts anywhere on your site.","categories":["widgets"],"code_type":"php","needs_auth":false},{"library_id":16242,"title":"Display Reading Time","code":"$reading_speed = 200; \/\/ 200 words per minute\r\n$content = get_post_field( 'post_content', get_the_id() );\r\n$word_count = str_word_count( strip_tags( $content ) );\r\n$reading_time = ceil( $word_count \/ $reading_speed );\r\n\r\necho '<p>Estimated reading time: ' . absint( $reading_time ) . ' ' . _n( 'minute', 'minutes', $reading_time ) . '<\/p>';","note":"Add the estimated reading time before the post content.","categories":["archive"],"code_type":"php","needs_auth":false},{"library_id":27160,"title":"Display Related Posts by Category","code":"global $post;\r\n\r\nif ( ! empty( $post ) ) {\r\n\t$categories = get_the_category( $post->ID );\r\n\r\n\tif ( $categories ) {\r\n\t\t$category_ids = array();\r\n\t\tforeach ( $categories as $category ) {\r\n\t\t\t$category_ids[] = $category->term_id;\r\n\t\t}\r\n\r\n\t\t$query_args = array(\r\n\t\t\t'category__in' => $category_ids,\r\n\t\t\t'post__not_in' => array( $post->ID ),\r\n\t\t\t'posts_per_page' => 5\r\n\t\t);\r\n\r\n\t\t$related_posts = new WP_Query( $query_args );\r\n\r\n\t\tif ( $related_posts->have_posts() ) {\r\n\t\t\techo '<div class=\"related-posts\">';\r\n\t\t\techo '<h3>Related Posts<\/h3><ul>';\r\n\t\t\twhile ( $related_posts->have_posts() ) : $related_posts->the_post();\r\n\t\t\t\techo '<li><a href=\"' . get_permalink() . '\">' . get_the_title() . '<\/a><\/li>';\r\n\t\t\tendwhile;\r\n\t\t\techo '<\/ul>';\r\n\t\t\techo '<\/div>';\r\n\r\n\t\t\twp_reset_postdata();\r\n\t\t}\r\n\t}\r\n}","note":"List 5 posts from the same categories as the current post.","categories":["archive","widgets"],"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, maybe_unserialize( $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":29710,"title":"Dynamic Greeting","code":"<div id=\"greeting-message\"><\/div>\r\n<script type=\"text\/javascript\">\r\n\tdocument.addEventListener( 'DOMContentLoaded', function () {\r\n\t\tconst morningGreeting = 'Good Morning!';\r\n\t\tconst afternoonGreeting = 'Good Afternoon!';\r\n\t\tconst eveningGreeting = 'Good Evening!';\r\n\r\n\t\tconst date = new Date();\r\n\t\tconst hour = date.getHours();\r\n\t\tlet greeting;\r\n\r\n\t\tif ( hour >= 5 && hour < 12 ) {\r\n\t\t\tgreeting = morningGreeting;\r\n\t\t} else if ( hour >= 12 && hour < 18 ) {\r\n\t\t\tgreeting = afternoonGreeting;\r\n\t\t} else {\r\n\t\t\tgreeting = eveningGreeting;\r\n\t\t}\r\n\r\n\t\tdocument.getElementById( 'greeting-message' ).textContent = greeting;\r\n\t} );\r\n<\/script>","note":"Use as Shortcode to display a greeting based on the time of day.","categories":["widgets"],"code_type":"html","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}, 1000 );","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":15139,"title":"Extend Login Expiration Time","code":"add_filter( 'auth_cookie_expiration', function () {\r\n\treturn 30 * DAY_IN_SECONDS; \/\/ 30 days in seconds.\r\n} );","note":"Toggling \"Remember Me\" will keep you logged-in for 30 days instead of 14 days.","categories":["login"],"code_type":"php","needs_auth":false},{"library_id":27162,"title":"Fading Page Transitions","code":"document.addEventListener(\"DOMContentLoaded\", function() {\r\n \/\/ Create and insert CSS styles for fade-in and fade-out\r\n const style = document.createElement('style');\r\n style.innerHTML = `\r\n .fade-out {\r\n opacity: 0;\r\n transition: opacity 0.5s ease-in-out;\r\n }\r\n .fade-in {\r\n opacity: 1;\r\n transition: opacity 0.5s ease-in-out;\r\n }\r\n `;\r\n document.head.appendChild(style);\r\n\r\n \/\/ Apply the fade-in effect on page load\r\n document.body.classList.add('fade-in');\r\n\r\n \/\/ Attach event listeners to all internal links for the fade-out effect\r\n document.querySelectorAll('a').forEach(anchor => {\r\n anchor.addEventListener('click', function(event) {\r\n if (anchor.hostname !== window.location.hostname) return;\r\n\r\n event.preventDefault();\r\n const target = this.href;\r\n\r\n document.body.classList.remove('fade-in');\r\n document.body.classList.add('fade-out');\r\n\r\n setTimeout(function() {\r\n window.location.href = target;\r\n }, 500); \/\/ Match this duration with the CSS transition time\r\n });\r\n });\r\n});","note":"Fade out the page when clicking on any internal links.","categories":["archive"],"code_type":"js","needs_auth":false},{"library_id":22993,"title":"FAQ Accordion","code":" $faqs = [\r\n [\r\n 'question' => 'What is your return policy?',\r\n 'answer' => 'Our return policy lasts 30 days. If 30 days have gone by since your purchase, unfortunately, we can\u2019t offer you a refund or exchange.'\r\n ],\r\n [\r\n 'question' => 'How do I track my order?',\r\n 'answer' => 'You will receive an email with a tracking number once your order has been shipped. You can use this number to track your order on our website.'\r\n ],\r\n [\r\n 'question' => 'Can I change my shipping address?',\r\n 'answer' => 'Yes, you can change your shipping address before the order is shipped. Please contact our support team to update your address.'\r\n ]\r\n ];\r\n ?>\r\n <style>\r\n .faq-section {\r\n width: 100%;\r\n max-width: 800px;\r\n margin: 0 auto;\r\n }\r\n .faq-item {\r\n border-bottom: 1px solid #ddd;\r\n margin-bottom: 10px;\r\n }\r\n .faq-question {\r\n cursor: pointer;\r\n padding: 15px;\r\n background: #f7f7f7;\r\n font-weight: bold;\r\n position: relative;\r\n transition: background-color 0.3s;\r\n }\r\n .faq-question:hover {\r\n background-color: #e2e2e2;\r\n }\r\n .faq-question::after {\r\n content: '\\25BC'; \/* Down arrow *\/\r\n position: absolute;\r\n right: 20px;\r\n transition: transform 0.3s;\r\n }\r\n .faq-question.expanded::after {\r\n transform: rotate(180deg); \/* Up arrow *\/\r\n }\r\n .faq-answer {\r\n display: none;\r\n padding: 15px;\r\n background: #fff;\r\n }\r\n <\/style>\r\n <div class=\"faq-section\">\r\n <?php foreach ($faqs as $faq): ?>\r\n <div class=\"faq-item\">\r\n <div class=\"faq-question\"><?php echo esc_html($faq['question']); ?><\/div>\r\n <div class=\"faq-answer\"><?php echo wp_kses_post($faq['answer']); ?><\/div>\r\n <\/div>\r\n <?php endforeach; ?>\r\n <\/div>\r\n <script>\r\n document.addEventListener('DOMContentLoaded', function() {\r\n var faqItems = document.querySelectorAll('.faq-item');\r\n\r\n faqItems.forEach(function(item) {\r\n var question = item.querySelector('.faq-question');\r\n question.addEventListener('click', function() {\r\n var answer = item.querySelector('.faq-answer');\r\n if (answer.style.display === 'none' || answer.style.display === '') {\r\n answer.style.display = 'block';\r\n question.classList.add('expanded');\r\n } else {\r\n answer.style.display = 'none';\r\n question.classList.remove('expanded');\r\n }\r\n });\r\n });\r\n });\r\n <\/script>","note":"Use this snippet as a shortcode to display frequently asked questions.","categories":["archive"],"code_type":"php","needs_auth":false},{"library_id":22999,"title":"Floating Social Media Icons","code":" \/\/ Define social media links\r\n $facebook_link = 'https:\/\/facebook.com\/yourprofile';\r\n $twitter_link = 'https:\/\/twitter.com\/yourprofile';\r\n $instagram_link = 'https:\/\/instagram.com\/yourprofile';\r\n $linkedin_link = 'https:\/\/linkedin.com\/in\/yourprofile';\r\n\r\n echo '\r\n <style>\r\n .floating-social-icons {\r\n position: fixed;\r\n top: 50%;\r\n left: 0;\r\n transform: translateY(-50%);\r\n z-index: 1000;\r\n }\r\n .floating-social-icons a {\r\n display: block;\r\n margin: 5px 0;\r\n width: 40px;\r\n height: 40px;\r\n background-color: #333;\r\n color: white;\r\n text-align: center;\r\n line-height: 40px;\r\n border-radius: 50%;\r\n transition: background-color 0.3s;\r\n }\r\n .floating-social-icons a:hover {\r\n background-color: #000;\r\n }\r\n .floating-social-icons a svg {\r\n width: 20px;\r\n height: 20px;\r\n fill: white;\r\n vertical-align: middle;\r\n }\r\n <\/style>\r\n <div class=\"floating-social-icons\">\r\n <a href=\"' . esc_url( $facebook_link ) . '\" target=\"_blank\" rel=\"noopener\">\r\n <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 24 24\">\r\n <path d=\"M22.675 0h-21.35c-.734 0-1.325.591-1.325 1.325v21.351c0 .733.591 1.324 1.325 1.324h11.494v-9.294h-3.125v-3.622h3.125v-2.672c0-3.1 1.892-4.787 4.654-4.787 1.325 0 2.463.099 2.794.143v3.241l-1.918.001c-1.504 0-1.795.715-1.795 1.763v2.311h3.587l-.467 3.622h-3.12v9.294h6.116c.733 0 1.324-.591 1.324-1.324v-21.351c0-.734-.591-1.325-1.324-1.325z\"\/>\r\n <\/svg>\r\n <\/a>\r\n <a href=\"' . esc_url( $twitter_link ) . '\" target=\"_blank\" rel=\"noopener\">\r\n <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 24 24\">\r\n <path d=\"M24 4.557c-.883.392-1.832.656-2.828.775 1.017-.611 1.798-1.574 2.165-2.724-.951.564-2.005.974-3.127 1.195-.897-.957-2.178-1.555-3.594-1.555-2.723 0-4.928 2.205-4.928 4.928 0 .386.043.762.127 1.124-4.094-.205-7.725-2.165-10.148-5.144-.424.729-.666 1.574-.666 2.475 0 1.708.869 3.215 2.19 4.099-.807-.026-1.566-.247-2.229-.616v.062c0 2.385 1.697 4.374 3.946 4.827-.413.112-.849.171-1.299.171-.317 0-.626-.031-.929-.088.626 1.956 2.444 3.379 4.6 3.419-1.68 1.318-3.799 2.105-6.1 2.105-.396 0-.788-.023-1.176-.069 2.179 1.396 4.768 2.212 7.548 2.212 9.054 0 14.004-7.498 14.004-13.986 0-.213-.005-.425-.014-.637.962-.693 1.797-1.562 2.457-2.549z\"\/>\r\n <\/svg>\r\n <\/a>\r\n <a href=\"' . esc_url( $instagram_link ) . '\" target=\"_blank\" rel=\"noopener\">\r\n <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 24 24\">\r\n <path d=\"M12 2.163c-3.204 0-3.584.012-4.85.07-1.366.062-2.633.336-3.608 1.311-.975.975-1.249 2.243-1.311 3.608-.058 1.266-.07 1.646-.07 4.85s.012 3.584.07 4.85c.062 1.366.336 2.633 1.311 3.608.975.975 2.243 1.249 3.608 1.311 1.266.058 1.646.07 4.85.07s3.584-.012 4.85-.07c1.366-.062 2.633-.336 3.608-1.311.975-.975 1.249-2.243 1.311-3.608.058-1.266.07-1.646.07-4.85s-.012-3.584-.07-4.85c-.062-1.366-.336-2.633-1.311-3.608-.975-.975-2.243-1.249-3.608-1.311-1.266-.058-1.646-.07-4.85-.07zm0-2.163c3.259 0 3.667.012 4.947.072 1.352.062 2.786.332 3.851 1.397 1.065 1.065 1.335 2.499 1.397 3.851.059 1.28.072 1.688.072 4.947s-.012 3.667-.072 4.947c-.062 1.352-.332 2.786-1.397 3.851-1.065 1.065-2.499 1.335-3.851 1.397-1.28.059-1.688.072-4.947.072s-3.667-.012-4.947-.072c-1.352-.062-2.786-.332-3.851-1.397-1.065-1.065-1.335-2.499-1.397-3.851-.059-1.28-.072-1.688-.072-4.947s.012-3.667.072-4.947c.062-1.352.332-2.786 1.397-3.851 1.065-1.065 2.499-1.335 3.851-1.397 1.28-.059 1.688-.072 4.947-.072zm0 5.838c-3.403 0-6.162 2.759-6.162 6.162s2.759 6.162 6.162 6.162 6.162-2.759 6.162-6.162-2.759-6.162-6.162-6.162zm0 10.324c-2.291 0-4.162-1.871-4.162-4.162s1.871-4.162 4.162-4.162 4.162 1.871 4.162 4.162-1.871 4.162-4.162 4.162zm6.406-11.845c-.796 0-1.441-.645-1.441-1.441s.645-1.441 1.441-1.441 1.441.645 1.441 1.441-.645 1.441-1.441 1.441z\"\/>\r\n <\/svg>\r\n <\/a>\r\n <a href=\"' . esc_url( $linkedin_link ) . '\" target=\"_blank\" rel=\"noopener\">\r\n <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 24 24\">\r\n <path d=\"M22.23 0h-20.46c-.976 0-1.77.794-1.77 1.77v20.46c0 .976.794 1.77 1.77 1.77h20.46c.976 0 1.77-.794 1.77-1.77v-20.46c0-.976-.794-1.77-1.77-1.77zm-15.785 20.452h-3.662v-11.97h3.662v11.97zm-1.831-13.62c-1.169 0-2.118-.948-2.118-2.117s.949-2.117 2.118-2.117c1.169 0 2.118.948 2.118 2.117s-.949 2.117-2.118 2.117zm15.085 13.62h-3.662v-5.789c0-1.379-.027-3.155-1.944-3.155-1.946 0-2.243 1.52-2.243 3.055v5.889h-3.662v-11.97h3.516v1.637h.05c.49-.933 1.688-1.917 3.476-1.917 3.715 0 4.401 2.444 4.401 5.621v6.629z\"\/>\r\n <\/svg>\r\n <\/a>\r\n <\/div>\r\n ';\r\n","note":"Display your Social Media accounts in a floating sidebar.","categories":["archive"],"code_type":"php","needs_auth":false},{"library_id":32238,"title":"Heartbeat Setting","code":"\/\/ Add a new setting in wp-admin > Settings > General\r\nadd_action( 'admin_init', function() {\r\n register_setting( 'general', 'custom_heartbeat_interval', 'intval' );\r\n add_settings_field( 'custom_heartbeat_interval', 'Heartbeat Interval', function() {\r\n $interval = get_option( 'custom_heartbeat_interval', 120 );\r\n echo \"<input type='number' name='custom_heartbeat_interval' value='\".absint($interval).\"' min='15' max='120' \/> seconds\";\r\n }, 'general' );\r\n});\r\n\r\nadd_filter( 'heartbeat_settings', function( $settings ) {\r\n $settings['interval'] = get_option( 'custom_heartbeat_interval', 120 );\r\n return $settings;\r\n});","note":"Add a setting that allows you to configure the heartbeat interval.","categories":["admin"],"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":25493,"title":"Hide \"Remember Me\"","code":"add_action( 'login_enqueue_scripts', function() { echo '<style type=\"text\/css\">.login .forgetmenot { display: none; }<\/style>'; } );","note":"Hide the \"Remember Me\" checkbox on the login page.","categories":["disable","login"],"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":29712,"title":"Inline Spoiler Shortcode","code":"\/\/ Hide text using the shortcode like this: [spoiler]hidden text here[\/spoiler].\r\nadd_shortcode('spoiler', 'inline_spoiler_shortcode');\r\nfunction inline_spoiler_shortcode($atts, $content = null) {\r\n \/\/ Start output buffering\r\n ob_start();\r\n\r\n \/\/ Output the spoiler content with the necessary styles\r\n ?>\r\n <span class=\"inline-spoiler\" style=\"color: transparent;\">\r\n <?php echo esc_html($content); ?>\r\n <\/span>\r\n <?php\r\n\r\n return ob_get_clean();\r\n}\r\n\r\nadd_action('wp_footer', 'inline_spoiler_script');\r\nfunction inline_spoiler_script() {\r\n ?>\r\n <style>\r\n\t\t.inline-spoiler {\r\n\t\t\tcolor: transparent;\r\n\t\t\tbackground-color: #333;\r\n\t\t\tborder-radius: 4px;\r\n\t\t\tpadding: 2px 4px;\r\n\t\t\tcursor: pointer;\r\n\t\t\ttransition: color 0.3s ease;\r\n\t\t}\r\n .inline-spoiler:hover {\r\n background-color: #444;\r\n }\r\n <\/style>\r\n <script type=\"text\/javascript\">\r\n document.addEventListener('DOMContentLoaded', function() {\r\n var spoilers = document.querySelectorAll('.inline-spoiler');\r\n spoilers.forEach(function(spoiler) {\r\n spoiler.addEventListener('click', function() {\r\n this.style.color = this.style.color === 'transparent' ? '#fff' : 'transparent';\r\n });\r\n });\r\n });\r\n <\/script>\r\n <?php\r\n}\r\n","note":"Easily hide spoilers in your text with a shortcode.","categories":["widgets"],"code_type":"php","needs_auth":false},{"library_id":25495,"title":"Last Login Column","code":"\/\/ Please note: This snippet will only show the last login date & time AFTER the snippet is activated.\r\n\/\/ The snippet has to be active to track the last login date & time.\r\n\r\n\/\/ Add a column to the users table to display the last login time\r\nadd_filter( 'manage_users_columns', function ( $columns ) {\r\n\t$columns['last_login'] = __( 'Last Login' );\r\n\r\n\treturn $columns;\r\n} );\r\n\r\n\/\/ Populate the last login column with data\r\nadd_filter( 'manage_users_custom_column', function ( $value, $column_name, $user_id ) {\r\n\tif ( 'last_login' === $column_name ) {\r\n\t\t$last_login = get_user_meta( $user_id, 'last_login', true );\r\n\t\tif ( $last_login ) {\r\n\t\t\t$value = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $last_login );\r\n\t\t} else {\r\n\t\t\t$value = __( 'Never' );\r\n\t\t}\r\n\t}\r\n\r\n\treturn $value;\r\n}, 10, 3 );\r\n\r\n\/\/ Record the last login time when a user logs in\r\nadd_action( 'wp_login', function ( $login, $user ) {\r\n\tupdate_user_meta( $user->ID, 'last_login', time() );\r\n}, 10, 2 );","note":"Add a column to the users table with the last time they logged in.","categories":["admin","login"],"code_type":"php","needs_auth":false},{"library_id":19978,"title":"Limit Comments & Display Character Count","code":"if ( ! class_exists( 'WPCode_Comment_Limit_Counter' ) ) {\r\n\tclass WPCode_Comment_Limit_Counter {\r\n\t\t\/\/ Update this value to change the maximum number of characters allowed in a comment.\r\n\t\tprotected $comment_max_length = 1000;\r\n\r\n\t\t\/\/ Update this value to change the minimum number of characters that a comment must have to go through.\r\n\t\tprotected $comment_min_length = 10;\r\n\r\n\t\tpublic function __construct() {\r\n\t\t\tadd_action( 'comment_form', array( $this, 'add_comment_counter_markup' ) );\r\n\t\t\tadd_action( 'comment_form', array( $this, 'add_comment_counter_js' ) );\r\n\t\t\tadd_filter( 'preprocess_comment', array( $this, 'prevent_long_comments' ) );\r\n\t\t}\r\n\r\n\t\tpublic function add_comment_counter_markup() {\r\n\t\t\t?>\r\n\t\t\t<div id=\"comment-counter\" style=\"margin-top: 10px;\">Characters:\r\n\t\t\t\t<span id=\"comment-counter-count\">0<\/span>\/<?php echo absint( $this->comment_max_length ); ?>\r\n\t\t\t<\/div>\r\n\t\t\t<?php\r\n\t\t}\r\n\r\n\t\tpublic function add_comment_counter_js() {\r\n\t\t\t?>\r\n\t\t\t<script type=\"text\/javascript\">\r\n\t\t\t\tdocument.addEventListener( 'DOMContentLoaded', function () {\r\n\t\t\t\t\tvar commentTextarea = document.getElementById( 'comment' );\r\n\t\t\t\t\tvar counterDisplay = document.getElementById( 'comment-counter-count' );\r\n\r\n\t\t\t\t\tfunction updateCounter() {\r\n\t\t\t\t\t\tcounterDisplay.textContent = commentTextarea.value.length;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tcommentTextarea.addEventListener( 'input', updateCounter );\r\n\t\t\t\t\tupdateCounter();\r\n\t\t\t\t} );\r\n\t\t\t<\/script>\r\n\r\n\t\t\t<?php\r\n\t\t}\r\n\r\n\t\tpublic function prevent_long_comments( $comment ) {\r\n\t\t\tif ( strlen( $comment['comment_content'] ) > $this->comment_max_length ) {\r\n\t\t\t\twp_die( sprintf( 'Comment is too long. Please keep your comment under %s characters.', $this->comment_max_length ) );\r\n\t\t\t}\r\n\t\t\tif ( strlen( $comment['comment_content'] ) < $this->comment_min_length ) {\r\n\t\t\t\twp_die( sprintf( 'Comment is too short. Please use at least %s characters.', $this->comment_min_length ) );\r\n\t\t\t}\r\n\r\n\t\t\treturn $comment;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nnew WPCode_Comment_Limit_Counter();\r\n","note":"Limit comment length and display a count of characters.","categories":["comments"],"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":17251,"title":"Limit Uploaded Image Size","code":"add_filter( 'wp_handle_upload', function ( $file ) {\r\n\t$max_width = 1920;\r\n\t$max_height = 1920;\r\n\r\n\t\/\/ Check if the file is an image.\r\n\t$mime_type = mime_content_type( $file['file'] );\r\n\tif ( strpos( $mime_type, 'image' ) === false ) {\r\n\t\treturn $file;\r\n\t}\r\n\r\n\t\/\/ Get the image size.\r\n\t$image_size = getimagesize( $file['file'] );\r\n\tif ( ! $image_size ) {\r\n\t\treturn $file;\r\n\t}\r\n\r\n\t\/\/ Check if the image is smaller than 1920px width or height.\r\n\tif ( $image_size[0] <= $max_width && $image_size[1] <= $max_height ) {\r\n\t\treturn $file;\r\n\t}\r\n\r\n\t\/\/ Resize the image.\r\n\t$image_editor = wp_get_image_editor( $file['file'] );\r\n\tif ( is_wp_error( $image_editor ) ) {\r\n\t\treturn $file;\r\n\t}\r\n\t$image_editor->resize( $max_width, $max_height );\r\n\t$image_editor->save( $file['file'] );\r\n\r\n\treturn $file;\r\n} );\r\n","note":"Set a max width and height for your image uploads to save space.","categories":["attachments"],"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":33961,"title":"Magnifier Glass For Images","code":"<script>\r\n(function() {\r\n \/\/ Configure these for your website.\r\n const containerSelector = 'body'; \/\/ Selector for containers with images\r\n const zoomLevel = 2; \/\/ Magnification zoom level\r\n const glassSize = 100; \/\/ Size of the magnifier glass in pixels\r\n const borderWidth = 3; \/\/ Border width around magnifier glass\r\n\r\n function magnify(img, zoom) {\r\n let glass, w, h, bw;\r\n \/* Create magnifier glass *\/\r\n glass = document.createElement(\"DIV\");\r\n glass.setAttribute(\"class\", \"img-magnifier-glass\");\r\n glass.style.width = glass.style.height = glassSize + \"px\";\r\n glass.style.borderWidth = borderWidth + \"px\";\r\n \/* Set background properties for the magnifier glass *\/\r\n glass.style.backgroundImage = \"url('\" + img.src + \"')\";\r\n glass.style.backgroundRepeat = \"no-repeat\";\r\n glass.style.backgroundSize = (img.width * zoom) + \"px \" + (img.height * zoom) + \"px\";\r\n bw = borderWidth;\r\n w = glassSize \/ 2;\r\n h = glassSize \/ 2;\r\n \/* Move the magnifier glass when mouse moves over the image *\/\r\n function moveMagnifier(e) {\r\n let pos, x, y;\r\n pos = getCursorPos(e);\r\n x = pos.x;\r\n y = pos.y;\r\n if (x > img.width || x < 0 || y > img.height || y < 0) {\r\n glass.style.display = \"none\";\r\n } else {\r\n glass.style.display = \"block\";\r\n glass.style.left = (x - w) + \"px\";\r\n glass.style.top = (y - h) + \"px\";\r\n glass.style.backgroundPosition = \"-\" + ((x * zoom) - w + bw) + \"px -\" + ((y * zoom) - h + bw) + \"px\";\r\n }\r\n }\r\n function getCursorPos(e) {\r\n let a, x = 0, y = 0;\r\n e = e || window.event;\r\n a = img.getBoundingClientRect();\r\n x = e.pageX - a.left - window.pageXOffset;\r\n y = e.pageY - a.top - window.pageYOffset;\r\n return { x: x, y: y };\r\n }\r\n \/* Insert magnifier glass *\/\r\n img.parentElement.insertBefore(glass, img);\r\n \/* Event listeners *\/\r\n img.addEventListener(\"mousemove\", moveMagnifier);\r\n img.addEventListener(\"mouseout\", function() {\r\n glass.style.display = \"none\";\r\n });\r\n img.addEventListener(\"mouseover\", function() {\r\n glass.style.display = \"block\";\r\n });\r\n }\r\n \/* Apply magnifier to images within specified container(s) *\/\r\n document.addEventListener(\"DOMContentLoaded\", function() {\r\n let containers = document.querySelectorAll(containerSelector);\r\n containers.forEach(function(container) {\r\n let images = container.getElementsByTagName('img');\r\n Array.prototype.forEach.call(images, function(img) {\r\n if (!img.parentElement.classList.contains('img-magnifier-container')) {\r\n let wrapper = document.createElement('div');\r\n wrapper.setAttribute('class', 'img-magnifier-container');\r\n img.parentNode.insertBefore(wrapper, img);\r\n wrapper.appendChild(img);\r\n magnify(img, zoomLevel);\r\n }\r\n });\r\n });\r\n });\r\n})();\r\n<\/script>\r\n<style>\r\n\/* Magnifier Glass Effect *\/\r\n.img-magnifier-container {\r\n position: relative;\r\n}\r\n\r\n.img-magnifier-glass {\r\n position: absolute;\r\n border: 3px solid #000;\r\n border-radius: 50%;\r\n box-sizing: border-box;\r\n cursor: none;\r\n width: 100px;\r\n height: 100px;\r\n display: none;\r\n pointer-events: none;\r\n}\r\n<\/style>","note":"Add a zoom effect to images on your website.","categories":["attachments"],"code_type":"html","needs_auth":false},{"library_id":17247,"title":"Maintenance Mode","code":"add_action( 'init', function() {\r\n\tif ( ! current_user_can( 'manage_options' ) && ! is_admin() && ! is_login() ) {\r\n\t\twp_die( 'This website is currently undergoing scheduled maintenance. Please try again later.' );\r\n\t}\r\n} );","note":"Display a simple maintenance mode message for non admin users.","categories":["admin"],"code_type":"php","needs_auth":false},{"library_id":43619,"title":"Markdown URLs for LLMs","code":"\/**\r\n * After enabling this snippet, go to Settings > Permalinks and click \"Save Changes\"\r\n * Configure the $enabled_post_types array to specify which post types should support .md URLs\r\n *\/\r\n$enabled_post_types = [ 'post', 'page' ];\r\n\r\n\r\n\/\/ Add rewrite rule to catch .md URLs\r\nadd_action( 'init', function () {\r\n\tadd_rewrite_rule(\r\n\t\t'(.+?)\\\\\\.md$',\r\n\t\t'index.php?markdown_url=$matches[1]',\r\n\t\t'top'\r\n\t);\r\n} );\r\n\r\n\/\/ Add custom query variable\r\nadd_filter( 'query_vars', function ( $vars ) {\r\n\t$vars[] = 'markdown_url';\r\n\r\n\treturn $vars;\r\n} );\r\n\r\n\/\/ Handle the markdown request\r\nadd_action( 'template_redirect', function () use ( $enabled_post_types ) {\r\n\t$markdown_url = get_query_var( 'markdown_url' );\r\n\r\n\tif ( ! $markdown_url ) {\r\n\t\treturn;\r\n\t}\r\n\r\n\t\/\/ Try to find the post by URL\r\n\t$post = ( function ( $url ) use ( $enabled_post_types ) {\r\n\t\t\/\/ Remove leading slash if present\r\n\t\t$url = ltrim( $url, '\/' );\r\n\r\n\t\t\/\/ Try to get post by URL path\r\n\t\t$post_id = url_to_postid( '\/' . $url );\r\n\t\tif ( $post_id ) {\r\n\t\t\treturn get_post( $post_id );\r\n\t\t}\r\n\r\n\t\t\/\/ If that doesn't work, try by post name\/slug\r\n\t\tforeach ( $enabled_post_types as $post_type ) {\r\n\t\t\t\/\/ Extract just the slug (last part after last slash)\r\n\t\t\t$slug = basename( $url );\r\n\r\n\t\t\t$posts = get_posts( [\r\n\t\t\t\t'name' => $slug,\r\n\t\t\t\t'post_type' => $post_type,\r\n\t\t\t\t'post_status' => 'publish',\r\n\t\t\t\t'numberposts' => 1\r\n\t\t\t] );\r\n\r\n\t\t\tif ( ! empty( $posts ) ) {\r\n\t\t\t\treturn $posts[0];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn null;\r\n\t} )( $markdown_url );\r\n\r\n\tif ( ! $post || ! in_array( $post->post_type, $enabled_post_types ) ) {\r\n\t\tstatus_header( 404 );\r\n\t\tnocache_headers();\r\n\t\techo \"Post not found or markdown not enabled for this post type.\";\r\n\t\texit;\r\n\t}\r\n\r\n\t\/\/ Generate markdown content\r\n\t$markdown_content = '';\r\n\t\/\/ Add title\r\n\t$markdown_content .= '# ' . get_the_title( $post ) . \"\\\\\\n\\\\\\n\";\r\n\t\/\/ Add metadata\r\n\t$markdown_content .= '**Published:** ' . get_the_date( 'F j, Y', $post ) . \"\\\\\\n\";\r\n\t$markdown_content .= '**Author:** ' . get_the_author_meta( 'display_name', $post->post_author ) . \"\\\\\\n\";\r\n\t\/\/ Add categories for posts\r\n\tif ( $post->post_type === 'post' ) {\r\n\t\t$categories = get_the_category( $post->ID );\r\n\t\tif ( ! empty( $categories ) ) {\r\n\t\t\t$cat_names = array_map( function ( $cat ) {\r\n\t\t\t\treturn $cat->name;\r\n\t\t\t}, $categories );\r\n\t\t\t$markdown_content .= '**Categories:** ' . implode( ', ', $cat_names ) . \"\\\\\\n\";\r\n\t\t}\r\n\t\t\/\/ Add tags for posts\r\n\t\t$tags = get_the_tags( $post->ID );\r\n\t\tif ( ! empty( $tags ) ) {\r\n\t\t\t$tag_names = array_map( function ( $tag ) {\r\n\t\t\t\treturn $tag->name;\r\n\t\t\t}, $tags );\r\n\t\t\t$markdown_content .= '**Tags:** ' . implode( ', ', $tag_names ) . \"\\\\\\n\";\r\n\t\t}\r\n\t}\r\n\t$markdown_content .= \"\\\\\\n---\\\\\\n\\\\\\n\";\r\n\t\/\/ Convert HTML content to markdown-friendly format\r\n\t$post_content = apply_filters( 'the_content', $post->post_content );\r\n\t\/\/ Basic HTML to Markdown conversion\r\n\t$post_content = ( function ( $html ) {\r\n\t\t$html = trim( preg_replace( '\/\\\\\\s+\/', ' ', $html ) );\r\n\t\t$html = preg_replace( '\/<h1[^>]*>(.*?)<\\\\\\\/h1>\/i', \"\\\\\\n# $1\\\\\\n\", $html );\r\n\t\t$html = preg_replace( '\/<h2[^>]*>(.*?)<\\\\\\\/h2>\/i', \"\\\\\\n## $1\\\\\\n\", $html );\r\n\t\t$html = preg_replace( '\/<h3[^>]*>(.*?)<\\\\\\\/h3>\/i', \"\\\\\\n### $1\\\\\\n\", $html );\r\n\t\t$html = preg_replace( '\/<h4[^>]*>(.*?)<\\\\\\\/h4>\/i', \"\\\\\\n#### $1\\\\\\n\", $html );\r\n\t\t$html = preg_replace( '\/<h5[^>]*>(.*?)<\\\\\\\/h5>\/i', \"\\\\\\n##### $1\\\\\\n\", $html );\r\n\t\t$html = preg_replace( '\/<h6[^>]*>(.*?)<\\\\\\\/h6>\/i', \"\\\\\\n###### $1\\\\\\n\", $html );\r\n\t\t$html = preg_replace( '\/<p[^>]*>(.*?)<\\\\\\\/p>\/i', \"$1\\\\\\n\\\\\\n\", $html );\r\n\t\t$html = str_replace( [ '<br>', '<br\/>', '<br \/>' ], \"\\\\\\n\", $html );\r\n\t\t$html = preg_replace( '\/<(strong|b)[^>]*>(.*?)<\\\\\\\/\\\\\\1>\/i', \"**$2**\", $html );\r\n\t\t$html = preg_replace( '\/<(em|i)[^>]*>(.*?)<\\\\\\\/\\\\\\1>\/i', \"*$2*\", $html );\r\n\t\t$html = preg_replace( '\/<a[^>]*href=[\"\\\\\\']([^\"\\\\\\']*)[\"\\\\\\'][^>]*>(.*?)<\\\\\\\/a>\/i', \"[$2]($1)\", $html );\r\n\t\t$html = preg_replace( '\/<img[^>]*src=[\"\\\\\\']([^\"\\\\\\']*)[\"\\\\\\'][^>]*alt=[\"\\\\\\']([^\"\\\\\\']*)[\"\\\\\\'][^>]*\\\\\\\/?>\/i', \"\", $html );\r\n\t\t$html = preg_replace( '\/<img[^>]*alt=[\"\\\\\\']([^\"\\\\\\']*)[\"\\\\\\'][^>]*src=[\"\\\\\\']([^\"\\\\\\']*)[\"\\\\\\'][^>]*\\\\\\\/?>\/i', \"\", $html );\r\n\t\t$html = preg_replace( '\/<img[^>]*src=[\"\\\\\\']([^\"\\\\\\']*)[\"\\\\\\'][^>]*\\\\\\\/?>\/i', \"\", $html );\r\n\t\t$html = preg_replace( '\/<ul[^>]*>\/i', \"\", $html );\r\n\t\t$html = preg_replace( '\/<\\\\\\\/ul>\/i', \"\\\\\\n\", $html );\r\n\t\t$html = preg_replace( '\/<ol[^>]*>\/i', \"\", $html );\r\n\t\t$html = preg_replace( '\/<\\\\\\\/ol>\/i', \"\\\\\\n\", $html );\r\n\t\t$html = preg_replace( '\/<li[^>]*>(.*?)<\\\\\\\/li>\/i', \"- $1\\\\\\n\", $html );\r\n\t\t$html = preg_replace_callback( '\/<blockquote[^>]*>(.*?)<\\\\\\\/blockquote>\/is', function ( $matches ) {\r\n\t\t\t$lines = explode( \"\\\\\\n\", trim( $matches[1] ) );\r\n\t\t\t$quoted = array_map( function ( $line ) {\r\n\t\t\t\treturn '> ' . trim( $line );\r\n\t\t\t}, $lines );\r\n\r\n\t\t\treturn \"\\\\\\n\" . implode( \"\\\\\\n\", $quoted ) . \"\\\\\\n\\\\\\n\";\r\n\t\t}, $html );\r\n\t\t$html = preg_replace_callback( '\/<pre[^>]*><code[^>]*>(.*?)<\\\\\\\/code><\\\\\\\/pre>\/is', function ( $matches ) {\r\n\t\t\treturn \"\\\\\\n```\\\\\\n\" . html_entity_decode( strip_tags( $matches[1] ) ) . \"\\\\\\n```\\\\\\n\\\\\\n\";\r\n\t\t}, $html );\r\n\t\t$html = preg_replace( '\/<code[^>]*>(.*?)<\\\\\\\/code>\/i', \"`$1`\", $html );\r\n\t\t$html = strip_tags( $html );\r\n\t\t$html = html_entity_decode( $html, ENT_QUOTES, 'UTF-8' );\r\n\t\t$html = preg_replace( '\/\\\\\\n\\\\\\s*\\\\\\n\\\\\\s*\\\\\\n\/', \"\\\\\\n\\\\\\n\", $html );\r\n\r\n\t\treturn trim( $html );\r\n\t} )( $post_content );\r\n\t$markdown_content .= $post_content;\r\n\t\/\/ Add permalink at the end\r\n\t$markdown_content .= \"\\\\\\n\\\\\\n---\\\\\\n\\\\\\n\";\r\n\t$markdown_content .= '**Original URL:** ' . get_permalink( $post ) . \"\\\\\\n\";\r\n\r\n\t\/\/ Set proper headers\r\n\tnocache_headers();\r\n\theader( 'Content-Type: text\/plain; charset=UTF-8' );\r\n\theader( 'Content-Disposition: inline; filename=\"' . sanitize_file_name( $post->post_name ) . '.md\"' );\r\n\r\n\t\/\/ Output the markdown content\r\n\techo $markdown_content;\r\n\r\n\t\/\/ Stop WordPress from processing further\r\n\texit;\r\n} );\r\n","note":"LLM-friendly WordPress content. Add .md to any post URL for AI-ready markdown format. Makes your...","categories":["archive"],"code_type":"php","needs_auth":false},{"library_id":13583,"title":"Move Admin Bar to the Bottom","code":"body {margin-top: -28px;padding-bottom: 28px;}\r\nbody.admin-bar #wphead {padding-top: 0;}\r\nbody.admin-bar #footer {padding-bottom: 28px;}\r\n#wpadminbar { top: auto !important;bottom: 0;}\r\n#wpadminbar .menupop .ab-sub-wrapper { bottom: 32px; }","note":"Move the admin bar to the bottom of the screen in the frontend.","categories":["admin"],"code_type":"css","needs_auth":false},{"library_id":17249,"title":"Open External Links in a New Tab","code":"add_filter( 'the_content', function ( $content ) {\r\n\t\/\/ This snippet requires the DOMDocument class to be available.\r\n\tif ( ! class_exists( 'DOMDocument' ) ) {\r\n\t\treturn $content;\r\n\t}\r\n\tif ( !is_single() || !in_the_loop() || !is_main_query() ) {\r\n\t\treturn $content;\r\n\t}\r\n\r\n\t$dom = new DOMDocument();\r\n\t$load_content = mb_convert_encoding( $content, 'HTML-ENTITIES', 'UTF-8' );\r\n\tif ( empty( $load_content ) ) {\r\n\t\treturn $content;\r\n\t}\r\n\t@$dom->loadHTML( $load_content );\r\n\t$links = $dom->getElementsByTagName( 'a' );\r\n\r\n\tforeach ( $links as $link ) {\r\n\t\tif ( strpos( $link->getAttribute( 'href' ), home_url() ) !== false ) {\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\t$old_link = $link->C14N();\r\n\t\t$link->setAttribute( 'target', '_blank' );\r\n\t\t$link->setAttribute( 'rel', 'noopener noreferrer' );\r\n\r\n\t\t$content = str_replace( $old_link, $link->C14N(), $content );\r\n\t}\r\n\r\n\treturn $content;\r\n} );\r\n","note":"Automatically open all external links added in posts in a new tab.","categories":["archive"],"code_type":"php","needs_auth":false},{"library_id":19982,"title":"Override Block Editor Palette Colors","code":"add_filter( 'wp_theme_json_data_theme', function ( $theme_json ) {\r\n\t$new_data = array(\r\n\t\t'settings' => array(\r\n\t\t\t'color' => array(\r\n\t\t\t\t'palette' => array(\r\n\t\t\t\t\t\/\/ Replace with your desired colors.\r\n\t\t\t\t\tarray(\r\n\t\t\t\t\t\t'slug' => 'white',\r\n\t\t\t\t\t\t'color' => '#ffffff',\r\n\t\t\t\t\t\t'name' => 'White',\r\n\t\t\t\t\t),\r\n\t\t\t\t\tarray(\r\n\t\t\t\t\t\t'slug' => 'black',\r\n\t\t\t\t\t\t'color' => '#000000',\r\n\t\t\t\t\t\t'name' => 'Black',\r\n\t\t\t\t\t),\r\n\t\t\t\t\tarray(\r\n\t\t\t\t\t\t'slug' => 'red',\r\n\t\t\t\t\t\t'color' => '#ff0000',\r\n\t\t\t\t\t\t'name' => 'Red',\r\n\t\t\t\t\t),\r\n\t\t\t\t\tarray(\r\n\t\t\t\t\t\t'slug' => 'green',\r\n\t\t\t\t\t\t'color' => '#00ff00',\r\n\t\t\t\t\t\t'name' => 'Green',\r\n\t\t\t\t\t),\r\n\t\t\t\t\tarray(\r\n\t\t\t\t\t\t'slug' => 'blue',\r\n\t\t\t\t\t\t'color' => '#0000ff',\r\n\t\t\t\t\t\t'name' => 'Blue',\r\n\t\t\t\t\t),\r\n\t\t\t\t),\r\n\t\t\t),\r\n\t\t),\r\n\t);\r\n\r\n\treturn $theme_json->update_with( $new_data );\r\n} );\r\n","note":"Use this snippet to control the pre-defined colors in the Block Editor.","categories":["admin"],"code_type":"php","needs_auth":false},{"library_id":16235,"title":"Post Meta Debugger","code":"add_action( 'add_meta_boxes', function () {\r\n\tif ( ! current_user_can( 'manage_options' ) ) {\r\n\t\t\/\/ Don't display the metabox to users who can't manage options\r\n\t\treturn;\r\n\t}\r\n\r\n\tadd_meta_box( 'wpcode-view-post-meta', 'Post Meta', function () {\r\n\t\t$custom_fields = get_post_meta( get_the_ID() );\r\n\t\t?>\r\n\t\t<table style=\"width: 100%; text-align: left;\">\r\n\t\t\t<thead>\r\n\t\t\t<tr>\r\n\t\t\t\t<th style=\"width: 28%\">Meta Key<\/th>\r\n\t\t\t\t<th style=\"width: 70%\">Value<\/th>\r\n\t\t\t<\/tr>\r\n\t\t\t<\/thead>\r\n\t\t\t<tbody>\r\n\t\t\t<?php foreach ( $custom_fields as $key => $values ) {\r\n\t\t\t\t?>\r\n\t\t\t\t<?php foreach ( $values as $value ) { ?>\r\n\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t<td><?php echo esc_html( $key ); ?><\/td>\r\n\t\t\t\t\t\t<td><code><?php echo esc_html( $value ); ?><\/code><\/td>\r\n\t\t\t\t\t<\/tr>\r\n\t\t\t\t<?php } ?>\r\n\t\t\t<?php } ?>\r\n\t\t\t<\/tbody>\r\n\t\t<\/table>\r\n\t\t<?php\r\n\t}, get_post_type() );\r\n} );","note":"Add a metabox that lists all the custom fields\/meta values for a post\/page for easy...","categories":["admin"],"code_type":"php","needs_auth":false},{"library_id":33957,"title":"Prevent Loading Translations","code":"add_filter( 'pre_load_textdomain', '__return_false', -5 );\r\nadd_filter( 'pre_load_script_translations', '__return_false', -5 );","note":"If your site is using en_US reduce the memory used for translation calls.","categories":["disable"],"code_type":"php","needs_auth":false},{"library_id":28380,"title":"Redirect 404 to Homepage","code":"add_action( 'template_redirect', function() {\r\n\tif (is_404()) {\r\n \twp_safe_redirect(home_url());\r\n\t exit();\r\n\t}\r\n} );","note":"Automatically redirect 404 pages to the homepage.","categories":["archive","disable"],"code_type":"php","needs_auth":false},{"library_id":21349,"title":"Remove \"WordPress\" from admin titles","code":"add_filter( 'admin_title', function ( $admin_title, $title ) {\r\n\treturn str_replace( \" — WordPress\", '', $admin_title );\r\n}, 10, 2 );","note":"Stop adding \"WordPress\" to the admin pages browser title.","categories":["admin","disable"],"code_type":"php","needs_auth":false},{"library_id":16238,"title":"Remove Color Scheme Picker","code":"add_action( 'admin_init', function() {\r\n\tremove_action('admin_color_scheme_picker', 'admin_color_scheme_picker');\r\n});","note":"Disable the option to change the admin color scheme in the profile page.","categories":["admin","disable"],"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":13590,"title":"Remove WP Block Library CSS","code":"add_action( 'wp_enqueue_scripts', function() {\r\n\twp_dequeue_style( 'wp-block-library' );\r\n\twp_dequeue_style( 'wp-block-library-theme' );\r\n}, 110 );","note":"Stop WordPress from loading the block editor CSS - especially useful if you don't use...","categories":["disable"],"code_type":"php","needs_auth":false},{"library_id":19980,"title":"Reorder Admin Menu Items","code":"add_filter( 'custom_menu_order', '__return_true' );\r\n\/\/ This will move the WPCode menu under the Dashboard menu item.\r\n\/\/ Uncomment and add more items as needed.\r\nadd_filter( 'menu_order', function () {\r\n\treturn array(\r\n\t\t'index.php',\r\n\t\t'wpcode',\r\n\/\/ \t\t'edit.php', \/\/ Posts\r\n\/\/ \t\t'upload.php', \/\/ Media\r\n\/\/ \t\t'edit.php?post_type=page', \/\/ Pages\r\n\/\/ \t\t'edit-comments.php', \/\/ Comments\r\n\t);\r\n} );","note":"Control the order of the admin menu items with a simple snippet.","categories":["admin"],"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":24307,"title":"Restore the Customize Submenu","code":"add_action( 'customize_register', '__return_true' );","note":"Add back the Customize menu under Appearance if your theme removes it.","categories":["admin"],"code_type":"php","needs_auth":false},{"library_id":16244,"title":"Scroll Progress Bar","code":"add_action('wp_body_open', function() {\r\n echo '<div id=\"wpcode-progress-bar\"><\/div>';\r\n});\r\n\r\nadd_action('wp_head', function() {\r\n echo '<style>\r\n #wpcode-progress-bar {\r\n position: fixed;\r\n top: 0;\r\n left: 0;\r\n width: 0%;\r\n height: 4px;\r\n background-color: var(--wp--preset--color--primary, #007bff); \/* Change the color as needed *\/\r\n z-index: 99;\r\n }\r\n\t\t@media( min-width: 769px ) {\r\n\t\t.admin-bar #wpcode-progress-bar {\r\n\t\t\ttop: 32px;\r\n\t\t}\r\n\t\t}\r\n <\/style>';\r\n});\r\n\r\nadd_action('wp_footer', function() {\r\n echo '<script>\r\n document.addEventListener(\"DOMContentLoaded\", function() {\r\n document.addEventListener(\"scroll\", function() {\r\n var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;\r\n var scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;\r\n var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;\r\n var scrolled = (scrollTop \/ (scrollHeight - clientHeight)) * 100;\r\n\r\n document.getElementById(\"wpcode-progress-bar\").style.width = scrolled + \"%\";\r\n });\r\n });\r\n <\/script>';\r\n});\r\n","note":"Display a progress bar at the top of the site as the user scrolls.","categories":["archive"],"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},{"library_id":27166,"title":"Show Active Plugins First","code":"add_filter('views_plugins', function($views) {\r\n global $wp_list_table;\r\n\r\n if (!is_network_admin() && isset($wp_list_table->items)) {\r\n $all_plugins = $wp_list_table->items;\r\n $active_plugins = get_option('active_plugins');\r\n\r\n $reordered_plugins = array();\r\n\r\n \/\/ Add active plugins first\r\n foreach ($all_plugins as $plugin_file => $plugin_data) {\r\n if (in_array($plugin_file, $active_plugins)) {\r\n $reordered_plugins[$plugin_file] = $plugin_data;\r\n }\r\n }\r\n\r\n \/\/ Add inactive plugins\r\n foreach ($all_plugins as $plugin_file => $plugin_data) {\r\n if (!in_array($plugin_file, $active_plugins)) {\r\n $reordered_plugins[$plugin_file] = $plugin_data;\r\n }\r\n }\r\n\r\n $wp_list_table->items = $reordered_plugins;\r\n }\r\n\r\n return $views;\r\n});","note":"List active plugins first in the wp-admin list of plugins.","categories":["admin"],"code_type":"php","needs_auth":false},{"library_id":22995,"title":"Simple Countdown Timer","code":"<div id=\"countdown\"><\/div>\r\n<script>\r\n function countdownTimer() {\r\n var endTime = new Date(\"December 31, 2025 23:59:59\").getTime();\r\n var now = new Date().getTime();\r\n var timeLeft = endTime - now;\r\n\r\n var days = Math.floor(timeLeft \/ (1000 * 60 * 60 * 24));\r\n var hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) \/ (1000 * 60 * 60));\r\n var minutes = Math.floor((timeLeft % (1000 * 60 * 60)) \/ (1000 * 60));\r\n var seconds = Math.floor((timeLeft % (1000 * 60)) \/ 1000);\r\n\r\n document.getElementById('countdown').innerHTML = days + \"d \" + hours + \"h \" +\r\n minutes + \"m \" + seconds + \"s \";\r\n\r\n if (timeLeft < 0) {\r\n clearInterval(x);\r\n document.getElementById('countdown').innerHTML = \"EXPIRED\";\r\n }\r\n }\r\n\r\n setInterval(function() { countdownTimer(); }, 1000);\r\n<\/script>","note":"Display a simple countdown timer using this snippet anywhere on your site.","categories":["widgets"],"code_type":"html","needs_auth":false},{"library_id":17255,"title":"Simple Table Of Contents","code":"add_filter( 'the_content', function ( $content ) {\r\n\t\/\/ This snippet requires the DOMDocument class to be available.\r\n\tif ( ! class_exists( 'DOMDocument' ) ) {\r\n\t\treturn $content;\r\n\t}\r\n\tif ( !is_single() || !in_the_loop() || !is_main_query() ) {\r\n\t\treturn $content;\r\n\t}\r\n\t$dom = new DOMDocument();\r\n\t$load_content = mb_convert_encoding( $content, 'HTML-ENTITIES', 'UTF-8' );\r\n\tif ( empty( $load_content ) ) {\r\n\t\treturn $content;\r\n\t}\r\n\t@$dom->loadHTML( $load_content );\r\n\t$xpath = new DOMXPath( $dom );\r\n\t$headings = $xpath->query( '\/\/h2 | \/\/h3' );\r\n\r\n\t\/\/ Let's loop through all the headings and add them to the table of contents.\r\n\t$headings_list = '<ul class=\"table-of-contents\">';\r\n\tforeach ( $headings as $heading ) {\r\n\t\t$heading_id = $heading->getAttribute( 'id' );\r\n\t\tif ( empty( $heading_id ) ) {\r\n\t\t\t\/\/ Generate a heading id and add it to the heading.\r\n\t\t\t$old_heading = $heading->C14N();\r\n\t\t\t$heading_id = sanitize_title( $heading->nodeValue );\r\n\t\t\t$heading->setAttribute( 'id', $heading_id );\r\n\t\t\t$content = str_replace( $old_heading, $heading->C14N(), $content );\r\n\t\t}\r\n\r\n\t\t$heading_text = $heading->nodeValue;\r\n\t\t$headings_list .= '<li><a href=\"#' . $heading_id . '\">' . $heading_text . '<\/a><\/li>';\r\n\t}\r\n\t$headings_list .= '<\/ul>';\r\n\t$content = $headings_list . $content;\r\n\r\n\treturn $content;\r\n} );","note":"Automatically add a table of contents from the headings in your posts.","categories":["archive"],"code_type":"php","needs_auth":false},{"library_id":27158,"title":"Smooth Scrolling for Anchor Links","code":"document.addEventListener('click', function(e) {\r\n \/\/ Check if the clicked element is an anchor with href starting with '#'\r\n if (e.target.tagName === 'A' && e.target.getAttribute('href') && e.target.getAttribute('href').startsWith('#')) {\r\n e.preventDefault();\r\n const targetId = e.target.getAttribute('href').slice(1); \/\/ Remove the '#' from the href\r\n const targetElement = document.getElementById(targetId);\r\n \r\n if (targetElement) {\r\n targetElement.scrollIntoView({\r\n behavior: 'smooth'\r\n });\r\n }\r\n }\r\n});\r\n","note":"Enables smooth scrolling for all on-page links with #.","categories":["widgets"],"code_type":"js","needs_auth":false},{"library_id":22991,"title":"Social Share Buttons","code":"$post_url = urlencode( get_permalink() );\r\n$post_title = urlencode( get_the_title() );\r\n\r\n$facebook_url = \"https:\/\/www.facebook.com\/sharer\/sharer.php?u=$post_url\";\r\n$x_url = \"https:\/\/twitter.com\/intent\/tweet?url=$post_url&text=$post_title\";\r\n$linkedin_url = \"https:\/\/www.linkedin.com\/shareArticle?mini=true&url=$post_url&title=$post_title\";\r\n\r\n$social_buttons = '\r\n <div class=\"social-share-buttons\">\r\n <a class=\"social-button\" href=\"' . esc_url( $facebook_url ) . '\" target=\"_blank\" aria-label=\"Share on Facebook\" rel=\"noopener\">\r\n <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path d=\"M22.675 0H1.325C.593 0 0 .593 0 1.325v21.351C0 23.407.593 24 1.325 24H12.82v-9.294H9.692v-3.622h3.127V8.413c0-3.1 1.894-4.785 4.659-4.785 1.325 0 2.464.099 2.794.143v3.24h-1.918c-1.504 0-1.794.714-1.794 1.763v2.31h3.587l-.467 3.622h-3.12V24h6.116C23.407 24 24 23.407 24 22.675V1.325C24 .593 23.407 0 22.675 0z\"\/><\/svg>\r\n <\/a>\r\n <a class=\"social-button\" href=\"' . esc_url( $x_url ) . '\" target=\"_blank\" aria-label=\"Share on X\" rel=\"noopener\">\r\n<svg width=\"24\" height=\"24\" viewBox=\"0 0 1200 1227\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\r\n <path d=\"M714.163 519.284L1160.89 0H1055.03L667.137 450.887L357.328 0H0L468.492 681.821L0 1226.37H105.866L515.491 750.218L842.672 1226.37H1200L714.137 519.284H714.163ZM569.165 687.828L521.697 619.934L144.011 79.6944H306.615L611.412 515.685L658.88 583.579L1055.08 1150.3H892.476L569.165 687.854V687.828Z\" \/>\r\n<\/svg>\r\n <\/a>\r\n <a class=\"social-button\" href=\"' . esc_url( $linkedin_url ) . '\" target=\"_blank\" aria-label=\"Share on LinkedIn\" rel=\"noopener\">\r\n <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path d=\"M22.23 0H1.77C.79 0 0 .77 0 1.73v20.54C0 23.23.79 24 1.77 24h20.46C23.21 24 24 23.23 24 22.27V1.73C24 .77 23.21 0 22.23 0zM7.12 20.45H3.56V9.02h3.56v11.43zM5.34 7.65c-1.14 0-2.06-.92-2.06-2.06 0-1.14.92-2.06 2.06-2.06s2.06.92 2.06 2.06c0 1.14-.92 2.06-2.06 2.06zM20.45 20.45h-3.56v-5.84c0-1.39-.03-3.18-1.94-3.18-1.94 0-2.24 1.51-2.24 3.07v5.95H9.02V9.02h3.42v1.56h.05c.48-.91 1.66-1.87 3.42-1.87 3.65 0 4.33 2.4 4.33 5.52v6.22z\"\/><\/svg>\r\n <\/a>\r\n <\/div>\r\n ';\r\n\r\necho $social_buttons;\r\n\r\n\/\/ Styles for the social sharing buttons.\r\necho '\r\n <style>\r\n .social-share-buttons {\r\n display: flex;\r\n gap: 10px;\r\n margin-top: 20px;\r\n }\r\n .social-button {\r\n display: inline-flex;\r\n align-items: center;\r\n justify-content: center;\r\n width: 40px;\r\n height: 40px;\r\n background-color: #f1f1f1;\r\n border-radius: 5px;\r\n text-decoration: none;\r\n }\r\n .social-button svg {\r\n fill: #555;\r\n }\r\n .social-button:hover svg {\r\n fill: #000;\r\n }\r\n <\/style>\r\n ';\r\n","note":"Add links to share articles to popular social media platforms.","categories":["archive"],"code_type":"php","needs_auth":false},{"library_id":29708,"title":"Special Offer Pop-up","code":"<?php\r\n\t\/\/ Customizable Settings.\r\n\t$offer_title = 'Special Offer!';\r\n\t$offer_message = 'Sign up now and get 20% off your first purchase.';\r\n\t$offer_button_text = 'Grab the Offer!';\r\n\t$offer_button_link = '\/your-special-offer-link'; \/\/ Update with the actual URL.\r\n\t$background_color = '#ffeb3b';\r\n\t$border_color = '#f1c40f';\r\n\t$text_color = '#333';\r\n\t$button_color = '#f1c40f';\r\n\t$button_hover_color = '#d4ac0d';\r\n\r\n\t?>\r\n\t<style>\r\n\t\t#special-offer {\r\n\t\t\tdisplay: none;\r\n\t\t\tposition: fixed;\r\n\t\t\tbottom: 20px;\r\n\t\t\tright: 20px;\r\n\t\t\twidth: 300px;\r\n\t\t\tpadding: 20px;\r\n\t\t\tbackground: <?php echo esc_attr( $background_color ); ?>;\r\n\t\t\tborder-radius: 5px;\r\n\t\t\tborder: 1px solid<?php echo esc_attr( $border_color ); ?>;\r\n\t\t\tbox-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);\r\n\t\t\tz-index: 1000;\r\n\t\t\tfont-family: Arial, sans-serif;\r\n\t\t}\r\n\r\n\t\t#special-offer h3 {\r\n\t\t\tmargin-top: 0;\r\n\t\t\tcolor: <?php echo esc_attr( $text_color ); ?>;\r\n\t\t}\r\n\r\n\t\t#special-offer p {\r\n\t\t\tcolor: <?php echo esc_attr( $text_color ); ?>;\r\n\t\t}\r\n\r\n\t\t#special-offer .offer-button {\r\n\t\t\tbackground-color: <?php echo esc_attr( $button_color ); ?>;\r\n\t\t\tcolor: #fff;\r\n\t\t\tpadding: 10px;\r\n\t\t\tborder: none;\r\n\t\t\tborder-radius: 3px;\r\n\t\t\tcursor: pointer;\r\n\t\t\ttext-align: center;\r\n\t\t\tdisplay: block;\r\n\t\t\tfont-size: 16px;\r\n\t\t\ttext-decoration: none;\r\n\t\t\tmargin-top: 10px;\r\n\t\t}\r\n\r\n\t\t#special-offer .offer-button:hover {\r\n\t\t\tbackground-color: <?php echo esc_attr( $button_hover_color ); ?>;\r\n\t\t}\r\n\r\n\t\t#close-offer {\r\n\t\t\tposition: absolute;\r\n\t\t\ttop: 5px;\r\n\t\t\tright: 5px;\r\n\t\t\tbackground-color: transparent;\r\n\t\t\tborder: none;\r\n\t\t\tfont-size: 16px;\r\n\t\t\tcursor: pointer;\r\n\t\t\tcolor: <?php echo esc_attr( $text_color ); ?>;\r\n\t\t}\r\n\t<\/style>\r\n\t<div id=\"special-offer\">\r\n\t\t<button id=\"close-offer\">×<\/button>\r\n\t\t<h3><?php echo esc_html( $offer_title ); ?><\/h3>\r\n\t\t<p><?php echo esc_html( $offer_message ); ?><\/p>\r\n\t\t<a href=\"<?php echo esc_url( $offer_button_link ); ?>\" class=\"offer-button\"><?php echo esc_html( $offer_button_text ); ?><\/a>\r\n\t<\/div>\r\n\t<script>\r\n\t\tdocument.addEventListener( 'DOMContentLoaded', function () {\r\n\t\t\tfunction shouldShowPopup() {\r\n\t\t\t\tvar dismissedTime = localStorage.getItem( 'specialOfferDismissed' );\r\n\t\t\t\tif ( !dismissedTime ) {\r\n\t\t\t\t\treturn true; \/\/ Never dismissed\r\n\t\t\t\t}\r\n\t\t\t\tvar now = Date.now();\r\n\t\t\t\tvar sevenDays = 7 * 24 * 60 * 60 * 1000; \/\/ 7 days to stay dismissed.\r\n\t\t\t\treturn ( now - dismissedTime ) > sevenDays;\r\n\t\t\t}\r\n\r\n\t\t\tif ( shouldShowPopup() ) {\r\n\t\t\t\tsetTimeout( function () {\r\n\t\t\t\t\tdocument.getElementById( 'special-offer' ).style.display = 'block';\r\n\t\t\t\t}, 2000 ); \/\/ Show after 2 seconds\r\n\t\t\t}\r\n\r\n\t\t\tdocument.getElementById( 'close-offer' ).addEventListener( 'click', function () {\r\n\t\t\t\tdocument.getElementById( 'special-offer' ).style.display = 'none';\r\n\t\t\t\tlocalStorage.setItem( 'specialOfferDismissed', Date.now() );\r\n\t\t\t} );\r\n\t\t} );\r\n\t<\/script>\r\n","note":"Display a small pop-up in the bottom-right of the page.","categories":["widgets"],"code_type":"universal","needs_auth":false}],"links":{"snippet":"https:\/\/library.wpcode.com\/api\/get\/"}}