Server Names based on Shrek

I’m a huge Shrek fan, so my first computer was called Shrek. Since then, all my (and my brother’s) computers/servers/devices have been named after Shrek characters. Often with a bit too much thought involved.

After about 10 years we realised we didn’t have a list of them anywhere.

To help us keep track, and in case anyone else finds it amusing – here’re our Shrek Server Names.

Computer/DeviceServer Shrek NameExplanation
Staging ServerMerlinMerlin is a magician who has good intentions and always tries his best. Just like code on staging servers – often it doesn’t work, but when it does it’s magical!
Mailserver & Backup ServerReggieReggie is one of the announcers of the group who come to summon Fiona & Shrek back to Far Far away. He’s part of a team who deliver messages (mail servers) he’s redundant (backup) and over enthusiastic (because you have to be over enthusiastic to run your own mailserver).
Backup ServerBroganBrogan is a leader of the ogre resistance and uses his nose as a horn, he gets captured (backups always break) but later saves the day (at least partially, always check your backups).
Sami’s Main PCShrekThe main character, and my main computer.
Sami’s LaptopDragonMy laptop is portable and gets hot. Just like Dragon.
Sami’s iPhoneCyclopsThat big, single eye in the top of my iPhone. Reminded me of Cyclops.
Docker HostCookieA Docker Host is a server which creates/runs lots of smaller servers. We often use it to try things out and see what sticks. Just like Cookie the Ogre Chef who catapults food to fight off the baddies.
HypervisorSwampA hypervisor is a server which lets you run lots of other servers. After Shrek and Fiona have kids the Swamp gets rather busy with lots of little ones running around, doing their thing.
Old School Linux ServerDonkeyWe’ve all got that big, old school server which just keeps ticking on and running things. Always there, often reliable is your trusty number 1 – Donkey.
Seafile ServerFairy God MotherShe makes and stores potions in her huge factory. Seafile is a Dropbx-style server for storing your precious files – magical and benign.
FirewallBig Bad WolfWho better to defend your networks against baddies than the Big Bad Wolf and his extraordinarily strong huffing and puffing.
Git ServerMuffin ManGit is used for managing code, and Muffin Man is the bakery where it’s all kept.
KubernetesKubernetes is a system for managing lots of different servers.
Puppet MasterPinocchioA terrible name. Thankfully we no longer use it, and hopefully we will be a bit more respectful of Pinocchio next time.
PHP 8 Production ServerLillian Lillian is a sensible, accepting and reliable person. So a good name for a new production server in 2022!
Category:

Repetitive Strain Injury is really bad – but can be avoided and healed (and there’s a book for it!)

tldr; Recognise the dangers of using your computer, avoid RSIs because they’re very hard to treat. Make time in your daily routine, because it’ll save you lots of time (and pain) later.

Repetitive Strain Injury. Personal Injury & Treatment Options by Clemens Conrad

I grew up on my computer, spending hours typing away – learning things, socialising, building things, playing games. It served me very well.

I also grew up with a family aware of good posture and taking breaks. Sure I never took as many as I should have, but I was aware enough that I didn’t have nearly as many problems as I should have done – given how long I spent hunched in front of a screen.

That was true until 2018, which for me was a crazy busy year. Too much went on, and the thing that got shafted was the breaks and the posture. Not Cool.

My Repetitive Strain Injury

In early 2019 I started getting pains in my wrist. Subtle at first, but over the course of only about two weeks they blew up into constant 24/7 sharp pains – with a background oscillation of other aches and pains.

I’ve lived a lucky life – I’ve never had excellent health, but I’ve never suffered from poor health. I’ve known people living with chronic pain and I know it’s a thing – but after just two weeks I realised quite how much it affects every aspect of your being.

Repetitive strain injuries are caused when you damage your nerves by repeating the same, usually small, movement too many times. “Too Many” is an awful lot, it took years and years of mouse clicking to cause the pain.

And it’s going to take years to resolve the pain, it seems.

The Path to Pain Free

RSIs are not well understood, so when fellow human being Clemens Conrad started suffering he did what many of us would like to do – the research! He had been let down by doctors, medicine, pills – everything he tried. Given the lack of information out there he started compiling his RSI story, and then other peoples stories.

What he’s compiled is the most useful resource book on Repetitive Strain Injury available. It’s not a magic answer, but it contains the information you need to find the answers which work for you. He makes no illusions about how difficult the task is, but by trying and following the advice in his book you can avoid doing what he had to do – dedicate a few years of his life to figuring this stuff out.

Who’s the book for?

If you’re an office (or factory) manager and your staff use computers – buy a copy of this book for your office. Incorporate it’s teachings, do a cost-benefit analysis of the risks of your staff developing RSI and taking sick time off work.

If you work on a computer, play video games or do any other repetitive task (Conrad’s page lists several common tasks) get this book and share it with your friends to help them prevent repetitive strain injury.

Get it before you need it, because then hopefully you’ll never need it.

Rsipain.com

Along with the book is a whole website full of free advice, most of what is in the book is free on the website (but for a website which largely says “Spend less time on your computer – of course there’s a book).

There’s software to help, exercises to do, though provoking re-thinkings of your world. There are literally dozens of suggestions, even if you just follow one or two you’ll reduce your risk.

https://www.rsipain.com/index.php

Disclaimer: I wrote this article in exchange for a free copy of the book – but Clemens Conrad had no input and if I didn’t actually love the book – I’d have declined and paid for it instead.

Category:

Deploying Laravel 5 & 6 to CloudWays using Envoyer

CloudWays has a super basic introduction to using Envoyer with CloudWays – but disapointingly it doesn’t actually cover any of the things specific to CloudWays. It’s just a generic introduction to a super basic deployment over SSH.

I’ve spent the best part of today getting things running, and wanted to share what I’ve done – to hopefully to help someone else, and also to request feedback from others.

I like automation, I don’t want to have to be doing things manually. That’s the purpose of Envoyer too. When I trigger a deploy in Envoyer, I expect my production site to be fully updated – composer, compiled assets, caches cleared, database migrated.

A little disclaimer

This process has been my attempt to set things up according to best practice. For me, best practice means automating as much as possible to eliminate human error (i.e. me forgetting to run something).

I’m setting this up in August 2019 – if anything doesn’t work well I’ll come back and update this blog (hopefully!). Otherwise please treat this as a suggestion, rather than something tried and tested. Likewise – I’d love your feedback or experiences in the comments below.

Deployment Hook Positions

Here are the Deployment Hooks I have setup, the content for each is in the table after. This one just shows where I’ve positioned each.

ActionBeforeAfter
Clone New ReleaseBackup
Install Composer DependenciesInstall NPM Dependencies, Build Assets
Activate New ReleaseRebuild Cache, Migrate DatabaseReset App Permissions on CloudWays, Restart FPM on CloudWays
Purge Old Releases

Deployment Hook Content

NameRun AsScript
Backupmaster# Backup the current site, before doing anything.
# Uses package: backpack/backupmanager
cd {{ project }}/current
php artisan backup:run
Install NPM Dependenciesmastercd {{release}}
npm install
Build Assetsmastercd {{release}}
npm run production
Rebuild Cachemastercd {{release}}
php artisan clear-compiled
php artisan cache:clear
php artisan view:clear
php artisan config:cache
Migrate Databasemastercd {{release}}
# Migrate the database without asking us
# if we’re sure.
php artisan migrate -n –force
Reset App Permissions in CloudWaysmasterCURL command (see blow). It was very long and messy to paste in this table.
Restart FPM on CloudWays master# Envoyer can’t restart FPM with the CloudWays SSH user
# but we can easily do it using the API.
CURL command (see blow). It was very long and messy to paste in this table.

Don’t forget to tick the “On Servers” box for each one, too.

Which user to deploy as?

One of the issues I’m trying to overcome is the occasional permissions issue I get in cache (especially template) files on CloudWays. Because I’m compiling my assets as the “master” user, but Apache is running them as the “application” user.

I started of trying to run everything as the application user. But that user cannot run npm properly (permissions issues creating ~/.npm).

I also tried to get the application user to build the assets and do the cache clearing – but again I was getting permissions issues and errors. I presume that’s something to do with the locked down users CloudWays configures.

So in the end – I’m running everything as the master user.

Using the CloudWays API

The CloudWays API is very simple to use, I used the Playground (don’t forget to Authourize with the button in the very top right) to generate the CURL call needed. Heads up: the Bearer header is not your API token, but is created when you authourise on the API Playground.

Grab the Server ID and Application ID by loading the CloudWays platform page and getting the numbers from the ID.

https://developers.cloudways.com/play/

CloudWays API Command to reset file permissions

Since I’m trying to avoid file permissions issues (caused by compiling things or clearing caches as the master user, but serving them as the application user) I opted to run CloudWays’s File Permission Re-setter tool after every deploy.

curl -X POST –header ‘Content-Type: application/x-www-form-urlencoded’ –header ‘Accept: application/json’ –header ‘Authorization: Bearer YOUR_API_TOKEN’ -d ‘server_id=YOUR_BEARER_ID&app_id=YOUR_APP_ID’ ‘https://api.cloudways.com/api/v1/app/manage/reset_permissions’

CloudWays API Command to restart FPM

Envoyer can’t restart FPM over SSH because CloudWays doens’t let us sudo. But we can do it with the API instead. Make sure you’ve got the correct PHP FPM version. Use the /service/get method to check what it should be.

curl -X POST –header ‘Content-Type: application/x-www-form-urlencoded’ –header ‘Accept: application/json’ –header ‘Authorization: Bearer YOUR_BEARER_TOKEN’ -d ‘server_id=YOUR_SERVER_ID&service=php7.3-fpm&state=restart’ ‘https://api.cloudways.com/api/v1/service/state’

Change Log

2019-10-08

  • Changed page title to include Laravel 6 – which I’m now using.
  • Moved “Build Assets” from “Before Activate New Release” to ” Before Install Composer Dependencies” to resolve “Mix Manifest not found” error.
  • Moved “Install NPM Dependencies ” from “After Install Composer Dependencies” to “Before Install Composer Dependencies” because it has to come before “Build Assets”

Comments, Suggestions, Feedback

As mentioned above, this is a voyage of discovery for me. Hopefully it’ll run smoothly going forward. I’ll definitely be adding to it (I intend to setup the Laravel Job Queue at some point).

Please share below any experience or suggestions you have. I struggled to find any detailed articles addressing this so hope to create one.

Category:

A Humanist Chanukah

I am by no means an authority on Humanism, I’ve met a few inspirational people who have been working on it for a lot longer than myself. However I’ve found it hard to find drop in alternatives to some of my families usual traditions. Rather than reinvent the wheel every year, I’m going to start writing them down – and doing so publicly so that others can comment and improve on them and perhaps find easy god-free ways to mark the passing seasons with their friends and families too.

What is Chanukah all about?

The first thing we need to do is figure out what Chanukah is about, why do we get together every year to light candles eat particular food? Some of these traditions will be specific to my personal preferences, my family, my community, my country and my ancestors traditions. Yours will probably differ – but that’s the joy of variety.

On Chanukah we:

Light the Chanukiah:

  • To count the days/mark the passing of time.
  • For an excuse to get together every day for a week (especially now that most of my siblings are living in difference places)
  • Because lights are pretty
  • To cheer us up at what can be a down-trodden time of year (it’s getting colder, it’s getting wet – but we’re not quite remembering our coat every time we leave the house).

Decorate the house – especially with lights

By the time Chanukah comes around, it’s usually dark when we leave work. It’s also dark when we get out of bed. Humans like daytime, we’re not nocturnal creatures. Brightening up our house – especially on the outside – is almost like saying “It’s dark, we might have street lights to see the path – but lets add colour to make us happy too”. We’re turning the darkness into happiness.

Give Presents

Because the giving and receiving of gifts is nice. Gift giving on Chanukah has actually become less central to my family as we’ve got older.

Gambling

The playing of Deeidel traditionally stems from when the Jews were prohibited from teaching Torah under the Greeks they would hide out in the forest to study Torah – if the Greek patrols came around they’d hide the learning materials and pull out spinning tops – pretending they were just playing with them.

Later on the Dreidel was incorporated into the Chanukah traditions and the letter was added to relate it to the Miracle of the Oil. This is inherently problematic for a humanist Chanukah which is trying to avoid the supernatural.

The tradition of gambling on Chanukah seems to stem from the Dreidel – rather than anything else. Gambling always starts with hope – even though you know that hope is usually not going to come about. This could tie in nicely with an idea that the story of Chanukah is about fighting for what you believe in – and of being hopeful but realistic.

Humanist Chanukah Ceremony

With all that in mind, perhaps we’re ready to put some words down.

Welcome to Chanukah

Chanukah is the Jewish festival of light. As the nights get longer and the days get colder it can be easy to contrast this season with the warm and bright summer which suddenly seems so long ago.

Spring might be only a few months away, but those months will be filled with not-enough-jumpers, forgotten rain coats and slippery pavements.

Festival of Light

As an antidote to this downtrodden time of year we try to bring more light into the world. We decorate our homes – inside and out. We make an extra effort to see our friends and families – to bring light into our hearts, but also to connect with them in advance of the tough season ahead – a season when many people struggle with ill health, cold houses, tough transport and isolation. It’s a chance to remind us of who we have, and to remind others that they can call on us if they need any assistance.

A Story of Hope

The story of Chanukah tells of a small band of people fighting for what they believe in against a great and mighty foe.

A little over 2000 years ago, the Greek King Antiochus took park in a popular activity for rulers throughout history – he banned the Jews from being Jewish. Taking over their temple and making a right old mess of it.

A brave Jew called Judah Maccabee (and his father, who’s name everyone forgets) fought back with their rag-tag gorilla fighers against the might of the Greek empire!

After a few years of struggle, the Maccabees won! They reclaimed their temple, and their freedom to be Jewish.

They cleaned up the temple, and rededicated it (the Hebrew word Chanukah means Dedication). They re-light the Menorah – the eternal flame which burned constantly in the Temple (and Synagogues to this day have a Ner Tamid – an Eternal Light – which is never switched off).

As much as they rummaged around, they could only find enough oil to last one day! And they needed 8 days to get new oil. Oh dear oh dear!

Ever optimistic, they light the Menorah anyway, and a miracle happened – the oil lasted 8 whole days! And that’s why we celebrate Chanukah for 8 days today.

A Story of Hope

The world today is full of so many rights, but also so many wrongs and we often feel helpless. Sometimes the biggest contributions we can make might still seem tiny in the grand scheme of things.

Even if I wasted nothing; travelled and ate responsibly; and considered the impact of my choices – would the world notice the impact?

No – it probably wouldn’t but if we were one of a thousand other people doing the same then the collective impact will all add up.

The Story of Chanukah is one of hope in the face of big issues, so whether you’re fighting to end animal cruelty, reduce environmental damage, to care for the needy or for a more just world – whatever your good fight is don’t give up on it.

Lighting the Lights

We’re now going to light the Chanukiah. We’ll be lighting all 8 branches because today is the 8th day of Chanukah. Once they’re lit, I’d like to invite you to spend some time enjoying their light and their warmth and to remember this moment when the whole world seems to be dark and cold.

Traditionally we would thank God for commanding us to do this, but God didn’t actually command us to light them. Instead we’ve written 8 kinds of light we are grateful for, and while we bask in the light of the Chanukiah we will read them out.

Now light the candles

8 Things for 8 Nights

As you light the candles, say one of the 8 Things below.

  1. I am grateful for the gentle light of the Chanukah candles
    1. Modeh Ani al ha’or ha’adin shel nerot Chanukah
    2. מודה אני על האור העדין של נרות החנוכה
  2. I am grateful for the morning light
    1. Modeh Ani al or ha’boker
    2. מודה אני על אור הבוקר
  3. I am grateful for the light of fire, which keeps us warm in the cold
    1. Modeh Ani al or ha’esh sh’machamem otanu b’choref ha’car
    2. מודה אני על אור האש שמחמם אותנו בחורף הקר
  4. I am grateful for the small light of the evening
    1. Modeh Ani al ha’or ha’katan shel ha’erev
    2. מודה אני על האור הקטן של הערב
  5. I am grateful for the light of the sun, from which all life comes
    1. Modeh Ani al Or Ha’Shemesh, Sheh’Mimenu Ma’gi’im Col Ha’Chaiot
    2. מודה אני על אור השמש, שממנו מגיעים כל החיים
  6. I am grateful for the light in our homes
    1. Modeh Ani al Ha’Or B’Bayitim Shelanu
    2. מודה אני על האור בבתים שלנו
  7. I am grateful for the light from the stars
    1. Modeh Ani Al Ha’Or Me’Ha’Cochav’im
    2. מודה אני על האור מהכוכבים
  8. I am grateful for the light within ourselves
    1. Modeh Ani al Ha’Or She’be’tochanu
    2. מודה אני על האור שבתוכנו
Category:

Why turning the lights off matters

This article was making the rounds on Social Media this afternoon, and I felt the desire to respond. Why Jewish Environmentalism is Pretty Useless
I was once asked what difference I thought I was making on my own, it’s not like I’m out converting 1,000 people to veganism – now that would make a real difference.
 
But for every 1 person converting 1,000 – there are 1,000 people quietly getting on with being a vegan. I was one of them.
 
The article seems to say that our individual actions don’t make a real difference, what we need is a change in society. Yet he then suggests that a change in society starts by talking to our neighbours – who are individuals.
 
I don’t agree with the sentiment, if our Synagogues work on helping our congregates to live sustainable lives, and churches, mosques, councils, scout groups and drinking buddies work with their communities then we’ll soon have a change in society.
 
The change, as I see it, is not that we need to be “more environmentally friendly” it’s that we need to stop only considering the financial and personal value of something. The race to the lowest price is why people choose unsustainable over sustainable, shop in supermarkets, buy electricity from coal.
 
Humans are lazy and averse to change, our parents and peers grew up eating whatever they wanted, buying snazzy new gadget and recreationally shopping. None of those are sustainable, but they’re tasty and fun so what the heck?
Category:

Object to the Hasmoneon Development on Copthall Fields

The decision is now with the Mayor of London

If you’d like to object to the planning application to build on the Copthall Fields (please do!) this is what you need to do, since Barnet (narrowly) approved it – it’s now with the mayor.

Click here to open your email client with the below details pre-filled.

Send your email:

To: [email protected]

CC: Andrew Dismore <[email protected]>

Subject: Objection to planning application Ref: 16/6662/FUL Hasmonean High School 2-4 Page Street London NW7 2EU

Body: In the body explain why you’re against.

Email Body Tips

Format your email body like this:

  1. A nice formal greeting. “To whom it may concern” or “Dear All”
  2. A sentence or two about who you are and your connection to the field. (e.g. a local resident, someone who explores London’s green spaces etc).
  3. List your reasons for objecting (only some things can be considered – pick them from the document below).
  4. Thank them for their time, and perhaps say you’re looking forward to their decision.
  5. Sign off with your full name and address (required, without your name and address the objection can’t be used).

You can only object on certain grounds, use this easy guide to see what you can object based on. You don’t need to write much, just mention why you’re objecting.

http://www.rtpi.org.uk/media/686895/Material-Planning-Considerations.pdf

Do this soon! The mayor only has another week or so to respond.

Share

Share this page with anyone you know who would value keeping places like this available to the public. Talk to your friends and neighbours.

Contact the local group of residents to see how you can help further:

Contact

Category:

Draft: Coder requests for Graphic Designers / How to design for code

WORK IN PROGRESS – this is a work in progress, if you have anything to add let me know here:  contact me!

Design is important, really important. Making things look right has an incredible impact on how visitors use our creations.

But not all design is essential, and not all styles are fixed.

Over many years of coding designs from mockups I’ve come across many habits graphic designers have which are very complicated to code.

So in my quest to ease Designer/Develoepr relations I’m compiling here a list of tips for designers to help them create designs which are easy (or not very messy) to code.

Naturally, if a design is wanted it can be coded. The Internet is magical like that – but if it doesn’t really matter if the logo is 2% larger on tablets than mobiles, lets keep them the same and keep the code sane.

Do use Rows

Everything on the web is either a rectangle or sits inside a rectangle.

You cannot see the rectangles which are responsible for layouts, but they’re still there. Making them overlap is possible, but not easy to do right.

Keeping things aligned in these invisible rows and columns makes coding life much easier.

Don’t make small changes

Every tiny visual change requires code to make the change and define when or where to apply the change. Having a button be 3px taller on the newsletter signup form than on the contact form requires about an extra 6 lines of code.

Don’t mix percentage and fixed widths

Having the form-labels be a fixed 150px wide and the form element take up the rest of the page is not fun to make happen in code. Either use percentage widths, or use fixed widths (which can be defined differently at different overall widths, but see “Don’t make small changes” above.

Category:

Pixel Density vs CSS

Pixel Density. This post is part sharing my research over the past few weeks, and part continuing it by requesting your feedback in the comments below.

Years ago everyone got excited for Retina and it’s high density pixels. Now every smart phone has it’s own configuration all the up to a Sony with 806ppi (a PC monitor usually has 72px).

The question is – how do we accommodate this so a phone can look awesome and a PC can still load fast and efficiently.

Vectors

The real answer, it seems, is to use vectors wherever possible. SVG support is here in all recent versions of all major browsers. Perfect for icons and fancy elements.

HTTP2 Push means we don’t even need to sprite them, but you still can if you wish.

Fonts are vectors, CSS is all vectors. Looking good.

Bitmaps

For bitmaps – photos and graphics – we have srcset so we can tell the browser which sizes of the image are available, and let the device pick the best size (based on pixel density, network speed, user preference – amazing!). Srcset works everywhere except IE (but srcset falls back to the old src way anyway, so no difference).

The PX Value in CSS

The big question is what do we do with “px” values in CSS – which are increasingly meaningless. They could just become an arbitrary CSS value which devices calculate against their Pixel-Ratio and that may well work forever.

Another possibility is do we use Viewport values for everything – one viewport value is 1% of the width or height of the viewport. It’s an exciting new value!

And guess what? Viewport Units are already widely supported!

Conclusion

In short: The situation is pretty great  🙂 The PX value is probably going to stick around for a bit (unless I’ve totally missed something) but devices know that and they’re happy to accommodate you for now.

Other Questions?

If you have other comments, or questions, leave them in the comments below.

 

Categories:

What Minimum Screen Size for Responsive Sites?

Until recently I’ve been testing responsive sites down to 320px out of habit but without really knowing whether it’s worth the effort. After all, Bootstrap 3 only has media queries down to 768px and Bootstrap 4 will be 34em (roughly/often 544px).

So should we bother optimising responsive websites for 320px, 480px, 768px or bring back the 1990s with Best Viewed in 800×600

I had a play with some stat from statcounter.com to find out.

My Process

  1. Show Screen Resolutions for the 12 months up to June 2016.
  2. Filters it for data for the UK (since most of my sites are mostly visited by people in the UK)
  3. Delete all screen resolutions wider than 1000px.
  4. Combine the matching widths – ignoring heights.
  5. Plot them on a graph

The Graph

The graph has two lines – one for individual market share and one for accumulative market share (i.e. how many people have 800px or smaller).

The aim was to find where the browser width jumps to a notable proportion.

responsive-webdesign-optimisation-width

The Results

The results are fascinating! 2.5% of visits come from a browser less than 720px wide but 15% have a screen bigger than that – and nearly double that have at least 800px.

The case for a minimum 720px Width

What to optimise for depends on your market – if you’re happy with 2.5% of your visitors getting frustrated that your site does not work – then don’t bother with less than 720px.

The case for a minimum 320px Wide Responsive Site

Optimising for 320px instead of 360px will only help 0.12% (one person in every thousand) use your site better – for a small business website getting 75 hits a day that’s one person every fortnight who’ll have a less than optimal time on your site.

Finding out who (or what, if they’re bots) are using very narrow screens would also be interesting. Are these bots, browser bugs or perhaps people just making a window smaller to get it out the way for a while? If they’re not your target audience, you can forget them and spend your time making the wider-screen experience excellent.

Raw Data

If you want to have a play yourself, here’s the data formatted as CSV:

Screen Width,Share %,Accumulative Share %
320px,0.121538461,0.121538461
360px,0.576923077,0.698461538
412px,0.049230769,0.747692307
480px,0.011538462,0.759230769
534px,0.244615385,1.003846154
540px,0.01,1.013846154
600px,0.947692308,1.961538462
601px,0.293846154,2.255384616
640px,0.063846154,2.31923077
720px,0.022307692,2.341538462
768px,12.76846154,15.11
800px,13.14846154,28.25846154
819px,0.019230769,28.27769231
854px,0.266153846,28.54384616
900px,0.016923077,28.56076923
911px,0.056153846,28.61692308
962px,0.011538462,28.62846154

Feedback

I’m not statistician and other interpretations of these results might be useful. If you have any feedback or other thoughts – let me know in the comments below.

Tags:
Categories:

WordPress Shortcodes for Website Editors

Overview of Shortcodes

WordPress Shortcodes are snippets of code which WordPress turns into more advanced things. For example the gallery shortcode is very simple in the editor, but turns into a complicated bunch of code for displaying many images.

A basic shortcode is a word wrapped in square brackets, like this:

[gallery]

Simple Shortcode

A shortcode to display the most recent posts might look like this:

[recent-posts]

you can put that anywhere you like in your post body and when you view it on the front-end of the website it’ll display a list of recent posts.

Closing Shortcodes

Some shortcodes can be wrapped around some text, for example a shortcode might make a paragraph stand out and flash. In this case you put the usual shortcode form above before the content, and a repeat of it but with a forward slash added after the first square bracked after the content.

[stand_out_and_flash]This is the content[/stand_out_and_flash]

The shortcode will then generate some code to go before and after the content – in this case to make it stand out and flash.

Shortcode Settings

A shortcode can also have settings – this lets you use the same shortcode in different places but with different results. Taking the example of the recent-posts shortcode above we might want to choose how many of the most recent posts to show. We do this by adding a space after the shortcode name, followed by the setting name, and equals and then the value – followed by the closing square bracket.

You can add as many settings as you like (as long as the shortcode supports them) by repeating the format.

If the value of the setting contains a space (or some other special characters) you need to put it in quotes (you can put all values in quotes if you prefer too).

You don’t repeat the settings in the closing shortcode (E.g. the [[/stand_out_and_flash]] – they are always just a forward slash followed by the shortcode name.

Here are some examples:

[recent-posts count=10 order="oldest first"]
[recent-posts count=5]
[stand_out_and_flash flash_speed=fast] This will flash really fast[/stand_out_and_flash]

Have any questions or tips about Shortcodes? Ask in the comments below.

Category: