Discover in this tutorial how to get and display all the themes of a WordPress installation using code.
It is possible that in some cases you may want to display (or get) all the themes of a WordPress installation, including version, author and other data.
So in this tutorial you are going to learn how you can get a listing of all the themes of a WordPress installation. This would be the result:
Let’s see it:
Steps to display all installed themes on a WordPress instance using a shortcode
1. Create the shortcode
First you are going to encapsulate the installed themes inside a shortcode so you can display the listing wherever you want.
Add the following code at the end of functions.php or in your functionality plugin:
With this code you create a shortcode that allows you to display a list with all the themes of the WordPress installation using the shortcode [theme_list].
To get the list of themes you use the
get_themes() function together with a foreach loop.
In this case, 3 details about the information of each theme are shown:
- Theme name
[Name]> with link to it
- Theme version
[Version]> with link to it [ThemeURI]
- Author’s name
[Author]> with link to it
But you can remove or add more to customize it to your liking. These are all the details you can display:
For example, for the Karma theme (from OsomPress) it returns something like this:
[Name] => Karma [ThemeURI] => https://demo.osompress.com/ [Description] => This is the Karma theme created for the Genesis Framework. [Author] => OsomPress [AuthorURI] => https://osompress.com/ [Version] => 2.0 [Template] => genesis [Status] => publish [Tags] => accessibility-ready, block-styles, custom-colors, custom-logo, custom-menu, editor-style, featured-images, footer-widgets, full-width-template, left-sidebar, one-column, right-sidebar, rtl-language-support, sticky-post, theme-options, threaded-comments, translation-ready, two-columns, wide-blocks [TextDomain] => karma [DomainPath] => [RequiresWP] => [RequiresPHP] =>
So you can customize the details you prefer to be displayed.
For example, if you want to display the parent theme you can use:
If you have any questions or suggestions you can leave them in the comments.
To be able to see the listing there is only one step left.
2. Insert the shortcode where you want
The advantage of shortcodes is that you can insert them anywhere on the web.
[theme_list] where you want it to be displayed.
- If you are using the classic editor, use the HTML tab to insert the shortcode.
- In case you are already using the new block editor (Gutenberg) you can add it to the normal paragraph block, the HTML block or the shortcode block. All of them will render the content correctly.
This would be an example of the listing that the shortcode would display:
Now you know how to get and display all the themes of a WordPress installation to decide if you need them all or not.
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂