To disable RSS feed pages in WordPress, hook into the action filters provided for each feed page function and then redirect to the home page. // Disable RSS feed pages add_action( ‘do_feed’, ‘disable_rss_feed_pages’, 1); add_action( ‘do_feed_rdf’, ‘disable_rss_feed_pages’, 1); add_action( ‘do_feed_rss’, ‘disable_rss_feed_pages’, 1); add_action( ‘do_feed_rss2’, ‘disable_rss_feed_pages’, 1); add_action( ‘do_feed_atom’, ‘disable_rss_feed_pages’, 1); add_action( ‘do_feed_rss2_comments’, ‘disable_rss_feed_pages’, 1); add_action(…
Category: WordPress
WordPress adding slashes in POST requests
WordPress adds slashes before quotes even if we do not want to use magic quotes. To solve this problem, you can use either of the following two functions on the values returned from POST requests- wp_unslash stripslashes_deep References: https://developer.wordpress.org/reference/functions/wp_unslash/ https://developer.wordpress.org/reference/functions/stripslashes_deep/ https://core.trac.wordpress.org/ticket/18322
How to Modify Title Tag in WordPress
I always missed a function to directly change the title tag in WordPress template. But here is a function which can do that for you. function modify_title( $new_title ) { add_action( ‘pre_get_document_title’, function( $current_title ) use( $new_title ) { return $new_title; }, 9999 ); } Please note that this function uses use keyword to bind…
WP_Query by URL for Infinite Scroll in WordPress
I was trying to create an infinite scroll in WordPress. All I wanted was to parse the next page url without making any changes to the code so that the code becomes interoperable with the pagination templates. To achieve that, instead of passing custom query parameters to the API, I decided to parse the next…
Reolved failed upload in WordPress post edit filter
When adding an upload form to the post edit screen in WordPress admin, I found the upload to fail. The $_FILES array was empty.The reason was that by default, WordPress post edit form does not send files data. To fix that, we need to add enctype attribute to the form.Here is the code to do…
How to customize PHP error message in WordPress
WordPress displays a default error message when it encounters a PHP error- There has been a critical error on this website. Learn more about troubleshooting WordPress. Now this message is subtle, but still reveals 2 things- Your website has some error Your website is built on WordPress Now second point is usually fine unless you…
How to change custom post permalink in WordPress
I have struggled with this issue for years. I tried different ways but they always felt like hacks and gave inconsistent results most of the time. I also tried a popular plugin which broke my site. Whenever you add a custom post type in WordPress through code, there is no way to select a permalink…
WordPress: Missing canonical tags on archive pages
WordPress keeps surprising me even after more than a decade since I started using it. Today I came to know that WordPress only generates canonical tags for singular pages (posts & pages). WordPress does not add canonical tags to archive pages including author page, post type archives, taxonomy archives etc. So, how to add canonical…
404 pages getting redirected to home
Today, I wasted major part of my day trying to figure out why my subfolder based WordPress multisite install is redirecting all 404 errors to the site’s home page. The problem turned out to be the constant “NOBLOGREDIRECT” which I defined in wp-config.php file. This constant ensures that in a multisite install, if anyone tries…
Modify page title tag in WordPress
To change page title tag in WordPress, use the pre_get_document_title filter. Most of the answers on web have mentioned the filter wp_title, but do not use it as wp_title function will be deprecated in future and wp_title hook will not work. At present, wp_title filter does not work when modifying the title tag.
Prevent Memory Leak in WordPress
Recently I faced an issue of memory leak in one of my WordPress projects. I was running a function that was reading post meta and user metadata of thousands of objects. I thought reading data from MySQL is cheap in terms of processing power and memory, but it turned out it was causing my function…
Correct Way to Manage Title Tags in WordPress
Correct way to add or modify title tags in WordPress using the latest theme support feature and the filter hook to dynamically modify it on the fly.
How to change Post Type in WordPress
Use these simple methods to easily change post type of single or multiple posts while working with multiple post types in WordPress.
How to view and modify WordPress rewrite rules
Sometimes a page load issue in your WordPress website has more to do with some random error rather than a bug in your code. In this case, it was rewrite rules cache.
Whitelist all sub-sites for wp_safe_redirect in WordPress Multisite
This article shows how to add all the domains/sub-domains of a WordPress multisite network to allow safe redirects through wp_safe_redirect function.
Where to add custom code in WordPress
Writing custom code for WordPress may be easy, but you should carefully add your code at the correct place to keep it clean and easily maintainable.
How to create a WordPress plugin
Easily create a simple WordPress plugin without any complex setup or need of FTP/SSH to your hosting server.
Enable Gzip compression in WordPress with htaccess
Gzip compression speeds up your Wordpress website by compressing the resources at the server level using simple .htaccess configuration in Apache server.
Correct file permissions for WordPress on Apache
Let us set up correct file permissions (chmod) for your Wordpress website to ensure the flawless functioning of your website and security from attacks.
Enable browser caching in WordPress using htaccess
Browser caching for all types of files can be easily done using Apache's .htaccess file. This simple configuration results in a faster website, less consumption of bandwidth and better user experience.