TOPIC: CANONICAL
Add Canonical Tags to WordPress without plugins
31st March 2025Search engines need to know which is which because they cannot know which is the real content when there is any duplication, unless you tell them. That is where canonical tags come in handy. By default, WordPress appears to add these for posts and pages, which makes sense. However, you can add them for other places too. While a plugin can do this for you, adding some code to your theme's functions.php file also does the job. This is how it could look:
function add_canonical_link() {
global $post;
// Check if we're on a single post/page
if (is_singular()) {
$canonical_url = get_permalink($post->ID);
}
// For the homepage
elseif (is_home() || is_front_page()) {
$canonical_url = home_url('/');
}
// For category archives
elseif (is_category()) {
$canonical_url = get_category_link(get_query_var('cat'));
}
// For tag archives
elseif (is_tag()) {
$canonical_url = get_tag_link(get_query_var('tag_id'));
}
// For other archive pages
elseif (is_archive()) {
$canonical_url = get_permalink();
}
// Fallback for other pages
else {
$canonical_url = get_permalink();
}
// Output the canonical link
echo '' . "\n";
}
// Hook the function to wp_head
add_action('wp_head', 'add_canonical_link');
// Remove default canonical link
remove_action('wp_head', 'rel_canonical');
The first part defines a function to define the canonical URL and create the tag to be added. With that completed, the penultimate piece of code hooks it into the wp_head
part of the web page, while the last function gets rid of the default link to get avoid any duplication of output.
Controlling display of users on the logon screen in Linux Mint 20.3
15th February 2022Recently, I tried using Commento with a static website that I was developing and this needed PostgreSQL rather than MySQL or MariaDB, which many content management tools use. That meant a learning curve that made me buy a book, as well as the creation of a system account for administering PostgreSQL. These are not the kind of things that you want to be too visible, so I wanted to hide them.
Since Linux Mint uses AccountsService
, you cannot use lightdm
to do this (the comments in /etc/lightdm/users.conf
suggest as much). Instead, you need to go to /var/lib/AccountsService/users
and look for a file called after the username. If one exists, all that is needed is for you to add the following line under the [User] section:
SystemAccount=true
If there is no file present for the user in question, then you need to create one with the following lines in there:
[User]
SystemAccount=true
Once the configuration files are set up as needed, AccountsService
needs to be restarted and the following command does that deed:
sudo systemctl restart accounts-daemon.service
Logging out should reveal that the user in question is not listed on the logon screen as required.
Removing the Guest Account Entry from Ubuntu 11.10 and Linux Mint 12 Login Screens
2nd December 2011Another feature of Ubuntu 11.10 and Linux Mint 12 is the appearance of a Guest Account entry on their login screens. Windows has had this feature for a while now, but it is easy to turn it off if you know where to look. Somehow, Ubuntu and Linux Mint haven't made it obvious as it could be. In both cases, you have to edit /etc/lightdm/lightdm.conf
and add the following line to the bottom of the file:
allow-guest=false
That removes the entry in question and could a little more security. On Ubuntu, there are lines in the file controlling the background image that you have for your login screen. In my experience, Linux Mint stores this in the greeter file referenced in lightdm.conf
and that's unity-greeter in my case, though, I mostly use GNOME 3 with only the occasional stint using the MATE desktop environment.
A lot of work ahead
6th December 2010Recently, I tested Ubuntu 11.04's first alpha release on both a VirtualBox VM and a spare PC. As expected with alpha software, it had issues. The new Unity desktop environment didn't work properly on either system: no top or side panels appeared, and applications lacked menu bars. Others appear to have had better experiences, possibly because they did fresh installations rather than upgrades like I did. I might try a clean install or wait for the next alpha release. The final version will include Firefox 4 along with the desktop changes. Overall, Natty Narwhal promises to be an unusually significant Ubuntu update. I'll monitor its development before deciding whether to upgrade. There's still plenty of time, as the release is months away.
Using the Windows Command Line for Security Administration
24th July 2009While there are point and click tools for the job, being able to set up new user groups, attach them to folders and assign users to them using the command line has major advantages when there are a number to be set up and logs of execution can be retained too. In light of this, it seems a shame that terse documentation along with the challenge of tracking down answers to any questions using Google, or whatever happens to be your search engine of choice, makes it less easy to discern what commands need to be run. This is where a book would help, but the whole experience is in direct contrast to the community of information providers that is the Linux user community, with Ubuntu being a particular shining example. Saying that, the Windows help system is not so bad once you can track down what you need. For instance, knowing that you need commands like CACLS
and NET LOCALGROUP
, the ones that have been doing the back work for me, it offers useful information quickly enough. To illustrate the usefulness of the aforementioned commands, here are a few scenarios.
Creating a new group:
net localgroup [name of new group] /comment:"[more verbose description of new group]" /add
Add a group to a folder:
cacls [folder address] /t /e /p [name of group]
The /t
switch gets cacls
to apply changes to the ACL for the specified folder and all its subfolders, a recursive action in other words, while the /e specifies ACL editing rather than its replacement and /p induces replacement of permissions for a given user or group. Using :n, :f, :c or :r directly after the name of a specified user or group assigns no, full, change (write) or read access, respectively. Replacing /p with /r revokes access, and leaving off the :n/:f/:c/:r will remove the group or user from the folder.
Add a user to a group:
net localgroup [name of group] [user name (with domain name if on a network)] /add
In addition to NET LOCALGROUP
, there is also NET GROUP
for wider network operations, something that I don't have cause to do. Casting the thinking net even wider, I suspect that VB
scripting and its ability to tweak the Windows Management Interface might offer more functionality than what is above (PowerShell also comes to mind while we are on the subject) but I am sharing what has been helping me, and it can be difficult to find if you don't know where to look.
Ubuntu: an appraisal of hardware support
31st October 2007After a painless start with Ubuntu, I have been able to overcome the obstacles placed in my way thus far. In fact, it is certain to yield a goodly number of blog posts, never a bad thing from my point of view. And so to this instalment...
For this post, I'll stick with the hardware side of things. Compared with previous voyages into the Linux universe, I have not encountered any "brick walls" placed in my path. Though audio support was one bugbear in the past, Ubuntu simply took care of that with no intervention from me. Then, I popped in a CD and music was played back to me, leaving me with the same confidence with MP3 files. In the same way, graphics were set up to my liking with having to lift a finger; while there is a proprietary ATI driver available, I'll stick with the standard set up since it easily works well enough for me. Printer set up needed a prod from my end, but it got on with things and found my HP LaserJet 1018 with nary a bother and all was set up rapidly. All other items of hardware but one scarcely merit a mention, so seamless was their detection and set up.
The one piece of hardware that made me work was my Epson Perfection 4490 Photo scanner. Though it wasn't supported out of the box, a spot of googling was all that it took to find out how to set things to rights. In fact, the best answer turned out to be on Ubuntu's forum, hardly a surprise really. The step-by-step instructions sent me over to Epson's repository of open source Linux drivers for the correct files; I did need to make sure I wasn't selecting 4990 in place of 4490, a straightforward thing to do. I snagged Debian RPM's and used alien to convert them to DEB files. Running dpkg as root did the installation and quick checks with the sane-find-scanner
and scanimage
commands revealed that all was well, to my clear relief.
Hardware support has always been an Achilles heel for Linux but, based on this experience, the Linux community seem to be more on top of it than ever before. The proprietary nature of the devices is an ever present challenge for driver developers, so getting as far as they have is an impressive achievement. It's a long way from roadblocks due to tempestuous support of modems, sound cards, printers and scanners and I seem to have got over the biggest hurdle on my Linux journey this time around.