{"id":434,"date":"2015-04-20T15:12:21","date_gmt":"2015-04-20T13:12:21","guid":{"rendered":"http:\/\/board.resabi.com\/?p=434"},"modified":"2015-04-20T15:12:21","modified_gmt":"2015-04-20T13:12:21","slug":"cool-wp-hacks-snippets","status":"publish","type":"post","link":"https:\/\/resabi.com\/board\/2015\/04\/20\/cool-wp-hacks-snippets\/","title":{"rendered":"More cool WP hacks and snippets to improve UX and security"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Working with WordPress on a daily basis I found or created many snippets that make maintenance easier, user experience better both for authors and visitors, or the website more flexible and secure. In the previous collection I shared <a title=\"6 useful WordPress tricks, hacks &amp; snippets\" href=\"http:\/\/board.resabi.com\/useful-wordpress-tricks-hacks-snippets\/\" target=\"_blank\" rel=\"noopener\">six useful hacks and snippets<\/a> for inserting ads, social sharing and security.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Today I&#8217;d like to share a few more of the simple tricks that will improve the security and user experience (both for visitors and staff) of your WordPress site.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prevent WP from adding links to images<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Add this piece of code to your theme&#8217;s functions.php file to disable the default linking when adding images. Note, this will not remove the existing links, just change the behavior when you add images.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282a37\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"<code&gt;function wpb_imagelink_setup() {\n\t$image_set = get_option( 'image_default_link_type' );\n\t\n\tif ($image_set !== 'none') {\n\t\tupdate_option('image_default_link_type', 'none');\n\t}\n}\nadd_action('admin_init', 'wpb_imagelink_setup', 10);<\/code&gt;\n\" style=\"color:#f8f8f2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Via <a href=\"http:\/\/www.wpbeginner.com\/wp-tutorials\/automatically-remove-default-image-links-wordpress\/\" target=\"_blank\" rel=\"noopener\">WP Beginner<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Disable comments for media (images)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Spammers just love to exploit these and when neglected you can get a huge amount of junk in your database. Unfortunately, from the media menu you can&#8217;t edit settings for all items comments at once, so you&#8217;re left with the frustrating job of changing one by one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Luckily, there&#8217;s also this piece of code that disables all media comments.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Via <a href=\"http:\/\/www.wpbeginner.com\/wp-tutorials\/how-to-disable-comments-on-wordpress-media-attachments\/\" target=\"_blank\" rel=\"noopener\">WpBeginner<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Replace WP logo with your own on WP-login<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/resabi.com\/board\/wp-content\/uploads\/2015\/04\/BMW-custom-WordPress-login.png\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"445\" src=\"https:\/\/resabi.com\/board\/wp-content\/uploads\/2015\/04\/BMW-custom-WordPress-login.png\" alt=\"Custom WordPress login\" class=\"wp-image-455\" srcset=\"https:\/\/resabi.com\/board\/wp-content\/uploads\/2015\/04\/BMW-custom-WordPress-login.png 720w, https:\/\/resabi.com\/board\/wp-content\/uploads\/2015\/04\/BMW-custom-WordPress-login-300x185.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This one is not that useful, but it&#8217;s cool, and if you build websites for clients, they&#8217;ll love it!<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282a37\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"function change_loginlogo() { echo '<style type=&quot;text\/css&quot;&gt; h1 a { background-image: url(' . get_template_directory_uri() . '\/images\/logo.png) !important; } <\/style&gt;'; } add_action('login_head', 'change_loginlogo');\" style=\"color:#f8f8f2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Via <a href=\"http:\/\/www.elegantthemes.com\/blog\/tips-tricks\/how-to-customize-the-wordpress-login-page\" target=\"_blank\" rel=\"noopener\">ElegantThemes<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">See also: <a href=\"https:\/\/codex.wordpress.org\/Customizing_the_Login_Form\" target=\"_blank\" rel=\"noopener\">Customizing the Login Form<\/a>, <a href=\"http:\/\/premium.wpmudev.org\/blog\/create-a-custom-wordpress-login-page\/\" target=\"_blank\" rel=\"noopener\">How to Create a Stunning Custom WordPress Login Page<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Add async and defer to javascript load<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This little function is useful for enhancing user experience and SEO through reducing page loading time. It tells the javascripts to defer and load asynchronously, without stopping the HTML parsing.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282a37\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"function defer_parsing_of_js ( $url ) { if ( FALSE === strpos( $url, '.js' ) ) return $url; if ( strpos( $url, 'jquery.js' ) ) return $url; return &quot;$url' async defer='defer&quot;; } add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );\" style=\"color:#f8f8f2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Via <a href=\"http:\/\/www.emoticode.net\/php\/add-async-and-defer-to-script-on-wordpress.html\" target=\"_blank\" rel=\"noopener\">Emoticode<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Remove script and css versions and meta generator<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These two functions make your WordPress installation a bit less obvious and, by hiding the version of your scripts and styles, a little harder for hackers to plan the attack.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"\" style=\"font-size:.875rem;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282a37\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"function remove_script_version( $src ){ return remove_query_arg( 'ver', $src ); } add_filter( 'script_loader_src', 'remove_script_version', 15, 1 ); add_filter( 'style_loader_src', 'remove_script_version', 15, 1 ); function remove_generator() { return ''; } add_filter('the_generator', 'remove_generator');\" style=\"color:#f8f8f2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Working with WordPress on a daily basis I found or created many snippets that make maintenance easier, user experience better both for authors and visitors, or the website more flexible and secure. In the previous collection I shared six useful hacks and snippets for inserting ads, social sharing and security. Today I&#8217;d like to share [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":455,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[11,12],"tags":[28,42],"class_list":["post-434","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uxui","category-wordpress","tag-snippets","tag-wp-tricks"],"_links":{"self":[{"href":"https:\/\/resabi.com\/board\/wp-json\/wp\/v2\/posts\/434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/resabi.com\/board\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/resabi.com\/board\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/resabi.com\/board\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/resabi.com\/board\/wp-json\/wp\/v2\/comments?post=434"}],"version-history":[{"count":0,"href":"https:\/\/resabi.com\/board\/wp-json\/wp\/v2\/posts\/434\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/resabi.com\/board\/wp-json\/wp\/v2\/media\/455"}],"wp:attachment":[{"href":"https:\/\/resabi.com\/board\/wp-json\/wp\/v2\/media?parent=434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/resabi.com\/board\/wp-json\/wp\/v2\/categories?post=434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/resabi.com\/board\/wp-json\/wp\/v2\/tags?post=434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}