WordPress Development – Themes, Plugins & Single Page Apps | Notes for developers
Developing themes and plugins for WordPress involves many different skills but there are some handy extensions, action hooks and filters to keep in mind either to speed up a project or following the best practice. How to define Custom Excerpts, Word Trimming, Mobile and Browser Detection You can detect if a user is on a
Developing themes and plugins for WordPress involves many different skills but there are some handy extensions, action hooks and filters to keep in mind either to speed up a project or following the best practice.
How to define Custom Excerpts, Word Trimming, Mobile and Browser Detection
You can detect if a user is on a mobile device using the wp_is_mobile() function. This function is not completely fool proof as it may return false positives.
WordPress will define numerous global variables from the database variable to variables about the current user.
The wp_trim_words() function is defined by WordPress which allows you to limit the amount of words in a string.
How to define Custom Author Fields and Avatars
WordPress provides 2 sets of hooks for editing and updating the user profiles. One set is for the user to update their own profiles and another set to allow users to modify other profiles.
The URL must be a live HTTP URL for avatars. Otherwise, you will not be able to use custom avatars.
How to image Cropping
An image that is soft cropped will be cropped to a specific dimension. However, if the image ratio can’t be kept intact, then WordPress will try it’s best to crop the image to the size you specified.
An image that is hard cropped will be cropped to an exact dimension. If the ratio can’t be kept intact, WordPress will cut the image so the size desired will be used.
If you decide to hard crop, then you have the ability to crop the image from certain positions like the center or top right corner.
It’s important that you regenerate all the thumbnails on an existing site because not all existing images will be resized.
How to edit the Main Query in the Home Page
You are allowed to modify the main query using a hook. The WP_Query class has a method called set() which allows you do to this.
Keep in mind that the hook will be applied to all pages and not just the home page. Make sure to perform checks to see what page you’r
e currently on.
The query_posts() function will also allow you to modify the main query, but it’s highly recommended you don’t use it.
How to debg – Debugging Hooks, Queries and Tools
There are many tools and techniques to debugging WordPress. Most of it is just preference.
WordPress still store all hooks and their functions inside the wp_filter global variable.
All queries are stored inside the wpdb->queries property. Only queries that have been executed will be stored.
The Query Monitor plugin will keep track of all queries, hooks, scripts, styles, requests and many more things for you.
How to Securing the wp-config File
WordPress will look for the config file inside the root installation or up one directory. It’s recommended you move it up one directory on a production server for extra security.
How to define SEO, Schema and Microdata
Microdata are attributes that you can apply to your elements to tell bots/crawlers more about the content it’s look at.
You are allowed to have types nested within each other. All types are children of the type Thing.
You can test your microdata using the structured data testing tool provided by Google. This tool will give you insight on what Google sees.
How to define RTL Support
RTL stands for right-to-left. There are languages that and read and written like this.
It’s optional to add support for these languages. You only need to check if the site is set to RTL using the is_rtl() function. If it is, then you’ll need to use CSS to make everything appear RTL.
Theme Unit Testing and ThemeForest Checklist
WordPress provides a set of instructions for unit testing your theme manually. It’s a very long process, but it can help catch bugs/problems you may have overlooked.
ThemeForest has it’s own set of requirements before you submit your theme for commercial sale. They have a very high standard of code quality.
The theme check plugin will scan your files for any errors, warnings and info about your theme.
oEmbed is a standard and not specific to WordPress. It’s how sites should provide embed code to other websites through code.
WordPress already takes care of this for you as it provides a couple of functions for making requests to oEmbed providers.
Child themes allow you to modify a theme without having to modify the parent theme files. Your code will be safe from being overridden as well.
To create a child theme you need to set the Template property to the parent theme folder.
It’s important that you correctly load both parent and child theme CSS files.
The process for translating a plugin/theme is called internationalization. WordPress utilizes the GetText PHP extension for translation strings.
Translating WordPress can be time consuming. It’s recommended you use a program like Po edit or Loco translate.
The pot file is template file translators can use as a start. The po file is the actual language file that will be compiled into mo file. The mo file is a server readable only file that contains all your translations.
Bundling Plugins with TGMPA
The TGM plugin activation class will help you with creating a UI and keeping track of what plugins the user should install.
Plugins can come from anywhere. They can be hosted from WordPress or come bundled with your theme.
Licensing and Making money with your Plugin/Theme
WordPress is licensed under GPL. This may be a problem if you want to sell your themes/plugins. This can lead to a problem called dual/split licensing.
You can sell your plugin/theme independently or you can sell on marketplaces such as CodeCanyon or ThemeForest.
Theme Starter Alternatives
Sometimes you’ll want to speed up the development process of creating a theme.
The best free starter theme is underscores. It comes with a lot of templates and utility functions for getting you started.
Genesis is a premium starter template with a lot of support and big community. Canvas is another starter template provided by WooCommerce.
Original Credits to louise ramirez jr.
Leave a Comment
FabioOctober 6, 2018
Hi, thanks for reading so far, leave a comment if it was of any help