Category: Wordpress Snippets
-

Protect wp-config.php with .htaccess – WordPress Code Snippets
[ad_1] To tighten security of your WordPress blog/website, you should prevent direct access to wp-config.php file. You can prevent this with htaccess. Adding this simple code to your .htaccess file will prevent unauthorized access to your wp-config.php file. # Disable direct access to wp-config.php <files wp-config.php> order allow,deny deny from all </files> [ad_2]
-

Open All External Links In New Window
[ad_1] Almost all web sites provide links to other sites, but it’s generally good practice to open these “external” links in a new window or tab. This makes it clear that the content is not part of your site, and also leaves your site open in the browser so the user can easily return. To…
-

Remove Width & Height Attributes From Uploaded Images
[ad_1] If you upload images via the WordPress media uploader and insert it into your post, it will automatically include the image width and height attribute in the html <img> tag. These are normally desirable, as it assists the browser in making the appropriate room for the image during layout. But for some reason if…
-

Force Use of www in All URLs And Redirect Traffic With .htaccess
[ad_1] A website can be accessed with http://www.domain.com and http://domain.com. If you visit any of these URLs, you will be sent to the same page but they will have different URLs. The main problem is that Google and other search engines consider it as duplicate content and therefore penalize this domain in the search engine…
-

Speed Up WordPress With Browser Caching
[ad_1] Browser caching can help to reduce server load by reducing the number of requests per page. By setting the correct file headers on static files that don’t change (like Images, CSS, JavaScript etc) browsers will then cache these files on the user’s computer. This technique allows the browser to check to see if files…
-

Remove WordPress Generator Meta Tag Completely
[ad_1] By default WordPress adds generator meta tag in website head section. The WordPress generator meta tag displays your website’s WordPress version for anyone to see. It can be considered a security risk to make your WordPress version visible and public. Because you are providing the hacker with the useful information by telling them which…
-

Limit Search Results For Specific Post Types
[ad_1] If you’re using a lot of custom post types then there are very good chance that your search results are displaying some content that you don’t want to display. Even sometimes you don’t want to include pages in search results too. So here is a simple solution to your problem. Adding this WordPress code…
-

Add Excerpt Support for WordPress Pages
[ad_1] By default WordPress does not allow excerpt to pages and it’s probably for good reason because normally you will never use it for pages. That’s why WordPress provides no option to add excerpts to pages through the WordPress admin panel but it’s fairly very easy to enable excerpt for pages too, similarly like posts.…
-

Add link to All Options in WordPress Admin Settings
[ad_1] WordPress have a secret options section that contains all core WordPress settings on one single page. Here’s a quick code snippet to display an “All Options” page to view otherwise hidden data. Just add that code to your theme’s functions.php file and then visit the settings menu in the WordPress admin panel. There you’ll…
-

Show All Media Attachments to a Post
[ad_1] Prior to WordPress 3.6, we had to run a query to retrieve all media attachments to a specific post. We had to do something like this. // show all WordPress post attachments $args = array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => -1, ‘post_status’ => ‘any’, ‘post_parent’ => $post->ID ); $attachments = get_posts( $args ); if…