Few weeks ago in one of the servers we faces strange issue: The website couldn’t send emails using remote SMTP.
First i thought it was related to SMTP port, credentials etc. – but everything was OK there. So then i tries to ping google.com and got surprised. It wasn’t worked. Simple ping didn’t work.
So it was obviously corrupted DNS issue.
First i tried the easier way, which is recommended by developers.google.com, adding Google DNS IP addresses to resolv.conf file
sudo vi /etc/resolv.conf
But it didn’t help.
So i decided to go into deeper and solving it using netplan.
Continue reading “How to use Google DNS in Ubuntu/Debian permanently”
In some mobile browsers PDF links might not work properly.
Instead of downloading, its tab just disappears immediately after opening. And we get no downloaded PDF.
Auto-close, auto-disappear – whatever you call that – but the problem exists.
So for WordPress websites, here is how to skip this pdf-download block for mobile browsers.
We will use pseudo-page link in order to bypass that block.
I mean, instead of direct links to PDF, we will use pseudo-pdf link which doesn’t look like PDF, but actually returns PDF header and body.
Let’s say that we have a PDF ile in “wp-content/uploads/2022.pdf”.
Continue reading “How to create downloadable PDF link that works in all mobile browsers – Chrome, Safari etc.”
Assume that we are using Fully cached static pages by any cache plugin. But we need to server some fresh content inside some block of the page.
To understand it easier let’s consider that we have fully cached homepage where there is a block about the number of your customers.
Something like this
Continue reading “Creating dynamic partial content in Cached WordPress Pages using Rest API”
Assume we have some plugin called AAA and it has built-in shortcode aaa_content and its usage is like this:
[AAA_content title=”Recent news” id=”23″]
Now we want to change its output HTML.
In WordPress, the output of any 3rd party function can be changed only if it has apply_filters() filtered output. Unfortunately not all functions and shortcodes have such filter in output. So it is almost impossible to modify its output without editing the plugin’s source file.
And as we know, editing the plugin file is always bad idea. The changes will be erased just in the next update.
So we have some different approach for such cases.
For example, here is one idea, which is subject of this blog post.
Creating parent shortcode which handles the output of the original shortcode.
So let’s declare and build that alternative shortcode.
Continue reading “How to modify the output of any WordPress shortcode”
What if you want to land different user roles to different pages? For example, admins should land to wp-admin, wholesalers should land to some /wholesaler page, default users should land to /shop page.
Continue reading “Set different landing pages by user-roles for WooCommerce Login”
In single-app, micro-service development almost all functions belong to you or to your team, so no need to know who defined the given function – you probably know it already.
But in CMS development some you may want to find the file where the given function is defined.
It might be WP core, template functions, theme or any of active plugins.
To find it you can use built-in PHP class called “ReflectionFunction”.
For example create such simple hook.
Continue reading “Find the file where the given function is defined”
You might want to get different product per pages for each category.
For example for Phones category, you want to display 10 phones per page, for Furniture, you want only 4 products per page, for Accessories, you want to display 100 products per page.
To achieve that is easy, here is how:
Continue reading “Set different “products per page” number for specified WooCommerce Category”
Say you are selling Phones, Tablets, Smart Watches etc. – and all of those are children of parent category called Gadgets. In this case you have probably faced non-relevant related-products in product-single page of your WooCommerce website.
So, the idea is this: To remove parent categories from related-categories algorithm and to force WooCommerce to show related categories by last child category only (tablets for a tablet, phones for a phone etc. not tablets for a phone)
So let’s write small snippet for this:
Continue reading “Remove parent categories from WooCommerce Related Products”