30 likes | 61 Views
Semalt, semalt SEO, Semalt SEO Tips, Semalt Agency, Semalt SEO Agency, Semalt SEO services, web design, web development, site promotion, analytics, SMM, Digital marketing
E N D
23.05.2018 Semalt Expert: How To Create A Simple WordPress Plugin Creating a custom WordPress plugin is easy. Most people may ?nd this aspect bene?cial to handle their modi?cations and many needs. Plugins are pieces of PHP code which alter the way your website operates. It is possible to create this code and add it to your WordPress website without having to modify the main code of the website. In some cases, you may need to add a unique feature to your site, one which does not have a ready-made commercial plugin. In this SEO article, provided by Andrew Dyhan, a leading expert from Semalt, you will learn how to create your custom WordPress plugin. Basic structure of a WordPress plugin In this SEO guide, we will focus on creating a WordPress plugin. This is a simple PHP ?le which contains some instructions in it. In my SEO opinion, it is always good to create a folder and put the PHP ?le inside. This folder should contain a similar name with the one on the plugin. After creating this ?le, it is essential to upload it to wp- content/plugins folder on your server host. A plugin has some few basics. For instance, there is the header. WordPress plugin header A simple header has a small functional structure which WordPress can recognize. For instance, it has: <?php https://rankexperience.com/articles/article1959.html 1/3
23.05.2018 Plugin Name: Our New Plugin This is the simplest format of a plugin header which is compatible with the WordPress content management system. By doing this step, you get a working plugin which you can be able to activate in your WordPress plugins area. However, there are no functions on it. Hence it will not alter any functionality of your website. The header can also contain some other information such as the author, description, version, etc. Some of this information may be necessary for future developmental purposes. The rest of the plugin There is no limit to the instructions you can put on your plugin. However, it is essential to consider the response of your website as a construction strategy. Putting too much code can make your site become heavily modi?ed. You can modify your plugin as much as you need. It is a simple PHP ?le which you can modify just like any theme, any modi?cation which you can make to your functions.php ?le. From a basic point, it is essential to minimize the changes which you can put in a WordPress website. For instance, I can use this snippet to help my website redirect a page to another, even on an entirely new website; function my_custom_redirect () { global $post; if ( is_page() || is_object( $post ) ) { if ( $redirect = get_post_meta($post->ID, 'redirect', true ) ) { wp_redirect( $redirect ); exit; add_action( 'get_header', 'my_custom_redirect' ); This snippet has one simple function. It can allow you to add a custom meta to any page. Furthermore, it can help you to add a custom 'redirect' using a different URL. In my previous header, the whole plugn would look like; <?php /* Plugin Name: Our New Plugin function my_custom_redirect () { global $post; if ( is_page() || is_object( $post ) ) { if ( $redirect = get_post_meta($post->ID, 'redirect', true ) ) https://rankexperience.com/articles/article1959.html 2/3
23.05.2018 wp_redirect( $redirect ); exit; add_action( 'get_header', 'my_custom_redirect' ); It is that simple to create a custom WordPress plugin. Like in the case above, we have made a plugin which can be able to redirect pages. You can also add a different line of PHP code to perform different functions on your WordPress website. https://rankexperience.com/articles/article1959.html 3/3