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”
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”
In my previous post about htaccess based restriction i showed how to restrict wp-admin or other file/page access by IP address. That’s very good solution when we are using VPN static IP.
But if we are using multiple connections (office, home, caffee, or multiple VPN-s with different IP addresses), then we need to have some easier solution.
And that can be cookie-based permission. Let’s see how to do that.
Continue reading “Cookie based permission in htaccess – restrict WordPress admin access by IP address”
WP-REST is great tool to connect 3rd party applications to your website and interact with it.
If you want to use it deeply in your website, you need to go to official website and read its handbook.
but what if you just want to use it for some small task and you don’t want to lose more time on reading docs? Then you might need JS code for frontend, and some backend codes for initialization and processing.
In this article i am giving you ready to use snippet, you just put it to your theme’s functions.php and it works.
Of course you will need to change the codes inside response function. In my example i am giving you an example which counts post_views.
Let’s create simple WordPress rest api custom endpoint. Here we go:
Continue reading “Ready to use snippet for WP REST API”
If you have several admin accounts, it is usual to see some options, settings changes where there is no any trace to see who has done that any change.
Of course it is not about Post, Page updates, they have some information about who updated the given post object.
But for the rest wp-admin pages there is no such trace collector.
Such kind of data can be useful if you have suspicion that someone you don’t have stolen admin password and logs in to your wp-admin as a wordpress ghost admin. So this snippet might be helpful when you want to stop/prevent wordpress admin panel hack too.
So, let’s write small snippet which will collect, who and when did any activity inside wp-admin.
Continue reading “How to log all WP-admin activities in WordPress”