21.09.2024
Home / Instructions / How to make a simple contact form for blogs on WordPress without using plugins. WordPress without a plugin – is it possible CSS pagination styles

How to make a simple contact form for blogs on WordPress without using plugins. WordPress without a plugin – is it possible CSS pagination styles

Hello! WordPress without plugins, what is it? The near future or another delusion inflated by narrow-minded people. Is it possible to create a website on WordPress without plugins? Of course you can! But the question is, who will create this site? Advanced webmaster or green teapot? What level and complexity will this site be without plugins? It is clear that a pro will make a website for you using just one code.

But that’s not the point, many people simply don’t understand that plugins are the same html, php, css, js code. By installing and activating a plugin, you add specific code to your site, the same code if you created the plugin function manually.

The only difference can be that when you install the plugin, a page with the plugin settings appears in your WordPress admin panel. But even then, not all plugins have settings and additional options. pages. Yes, there are heavy plugins that add many pages with settings, outgoing links, advertising, etc. to your admin panel. But, again, if you are (which is recommended to do), then what difference does it make to you?! Search engines Access to your admin panel will be blocked.

It turns out that, in fact, there is only one minus - the weight of the plugin, everything else does not matter. And the weight of the plugin is not so scary, what is 50 - 100 megabytes? This is nothing if your hosting has from 10 to 100 gigabytes of disk memory. This is just funny!

Sometimes there are problems with incompatibility, but this is normal, everyone’s topics are different, anything can happen. If the plugin somehow negatively affects your site, then simply remove it, what's the problem? Look for another plugin that suits you. One of the popular misconceptions is that plugins slow down your website. This is another nonsense from narrow-minded people! You also need to look for a plugin that will significantly slow down your site.

You can install 50 plugins and your site will be fine, or you can install a couple of plugins and you will lose 0.2-0.5 seconds when loading the page. But again, this is funny, as they say - Beauty requires sacrifice, this is normal.

They are far from hidden in the plugins, all this is nonsense of people who do not understand and do not even know the true reasons. It turns out that all these rumors, speculations, stereotypes about the harm of plugins are all pure nonsense and insanity! The man read on the fence that Petka is a fool and now he is convinced that Petka is a real fool and a scoundrel, although he doesn’t know him by sight!

WordPress plugins are a real revolution in the field of website building, now you don’t need to be a professional web programmer, etc. to create your website. All you need is to be able to read, some brains and time.

There are many that are simply mind blowing, these are really super effective tools that will provide you with maximum benefit. Yes, it takes a lot of time to sort through this whole mountain of plugins and find exactly what you need, but believe me, it’s worth it. On at the moment With the help of plugins you can create absolutely anything, any site, any function, you just need to search, search and search again and in the end you will find and you will be amazed at how simple everything is. Oh this magical world of WordPress, which surprises more and more every day...

We continue the series of posts dedicated to feedback in the WordPress management system. Today I will try to tell you how to do it without a plugin based on the standard wp_mail function using ajax programming technology.

Benefits of WordPress feedback without a plugin

  • The site does not load extra JavaScript and CSS code - it becomes easier;
  • WordPress feedback form without a plugin is less prone to spam, provided that your code is unique;
  • You can customize the output to your liking and create a form of any complexity.

In order to create a WordPress feedback form, without using plugins, we need a minimum of PHP knowledge, just copy the code to the right place.

Code for creating WordPress feedback without a plugin

Let's get started!

Open the functions.php file of your theme and add the following code there:

function myform_action_callback() ( global $wpdb; global $mail; $nonce=$_POST["nonce"]; $rtr=""; if (!wp_verify_nonce($nonce, "myform_action-nonce")) wp_die("(" error":"Error. Spam")"); $message=""; $to="your_mail@site"; // replace with your email $headers = "Content-type: text/html; charset=utf-8 \r\n"; $headers.= "From: [email protected]\r\n"; // replace with another mailbox $subject="Message from the site ".$_SERVER["SERVER_NAME"]; do_action("plugins_loaded"); // does not need to be enabled in new VIs, you may need to disable it if ( !empty($_POST["name"]) && !empty($_POST["mess"]) && !empty($_POST["email"]))( $message.="Name: ".$_POST[" name"]; $message.="
E-mail: ".$_POST["email"]; $message.="
Message:
".nl2br($_POST["mess"]); if(wp_mail($to, $subject, $message, $headers))( $rtr="("work":"Message sent!","error": "")"; )else( $rtr="("error":"Server error.")"; ) )else( $rtr="("error":"All fields are required!")"; ) echo $rtr; exit; ) add_action("wp_ajax_nopriv_myform_send_action", "myform_action_callback"); add_action("wp_ajax_myform_send_action", "myform_action_callback"); function myform_stylesheet())( wp_enqueue_style("myform_style_templ",get_bloginfo("stylesheet_directory")."/css /styleform.css","0.1.2",true); wp_enqueue_script("myform_script_temp",get_bloginfo("stylesheet_directory")."/js/scriptform.js",array("jquery"),"0.1.2", true); wp_localize_script("myform_script_temp", "myform_Ajax", array("ajaxurl" => admin_url("admin-ajax.php"), "nonce" => wp_create_nonce("myform_action-nonce"))); "wp_enqueue_scripts", "myform_stylesheet"); function formZak() ( $rty="

"; $rty.="
"; $rty.="
"; $rty.="
"; $rty.="
"; $rty.="
"; return $rty; ) add_shortcode("formZak", "formZak");

In the first function "myform_action_callback" you need $to="your_mail@site"; - replace with your email. You may also have problems with the line do_action("plugins_loaded"); - on new versions of the VP you can do without it. There is no need to change anything else, the example is working and WordPress feedback without a plugin was tested on WP versions 4.2 and 4.9.1.

Following from this code, you need to create 2 folders in the theme: "css" and "js". If these directories are already present in your theme, there is no need to create them. Place the style file "styleform.css" into the "css" directory - and, if desired, write the form styles there. I won’t do this, since styles are not needed for the example to work.

Place the file “scriptform.js” in the “js” directory and write this simple code there:

function myform_ajax_send(name,email,mess)(
jQuery.ajax((
type: "POST",
url: myform_Ajax.ajaxurl,
dataType:"json",
data:(
"name":jQuery(name).val(),
"email":jQuery(email).val(),
"mess":jQuery(mess).val(),
"nonce": myform_Ajax.nonce,
"action":"myform_send_action"
},
success: function (data) (
if(data.error=="")(
alert(data.work);
)else(
alert(data.error);
}
},
error: function() (
alert("Connection error");
}
});
}

Don't forget to upload these files to your server.

Everything is ready! - in order to display the form, just insert the shortcode into a post or page of your website.

If you need to call a form from PHP, for example at the bottom of the page, use the shortcode call:

You can copy this code to your website and try to test it, everything should work, I specifically tested this example on myself. This is the response you should receive by email:

As you understand, this is how easy it is to do without a plugin. Next I’ll try to tell you a little about what this code means, if of course you’re interested.

Description of feedback for wordpress without plugin

myform_action_callback() - a function for sending a message from the feedback form to your email.

add_action("wp_ajax_nopriv_myform_send_action", "myform_action_callback");
add_action("wp_ajax_myform_send_action", "myform_action_callback");

connect our sending function to the Ajax request. Important point The point is that from here “myform_send_action” should match this line in your JavaScript file: “action”: “myform_send_action”

myform_stylesheet() - a function for connecting a style file, JavaScript and creating a JavaScript variable myform_Ajax, which includes myform_Ajax.ajaxurl - a link to the Ajax request handler and myform_Ajax.nonce - a unique check that the form was sent from your site (needed to prevent spam and site hacking).

formZak() - function where the form code is generated. Here we can add or remove the required fields.

Last line of functions: add_shortcode("formZak", "formZak"); registers a shortcode so that it is convenient for us to work with our feedback form for WordPress without a plugin.

I decided to create a small table to structure the files that you need to create or into which you need to add code in order for WordPress feedback to work without a plugin. There are not many of them, I think you can figure it out.

It seems like I described everything about how to create a feedback form without plugins. If you still have questions about the code, or you were unable to run this form on your server, you can describe the problem in the comments. I will be glad to help solve your problem. Until next time.

Unfortunately, you won’t be able to download this example, since I can’t provide my functions.php file to your theme, it simply won’t work :(.

If you find problems in the operation of this code, please let us know, we will be grateful. Trouble is possible due to updating the VI and disabling some of the used functions, or when switching to a new jquery library.

I now have a new hobby - optimizing my blog on the WordPress engine. "Network Path" in such a way as to preserve functionality and at the same time avoid no plugins

The dislike for plugins did not arise out of nowhere. Sometime in the fall, I decided that the capabilities of my hoster were becoming insufficient and moved to another one. And to make it really good (as I thought to myself) - on a virtual dedicated server

My poor blog. How many experiments have already been carried out on it! Another would have simply covered himself with a copper basin and not gurgled. Overall, the move turned out to be a strategic mistake. The dedicated line cost many times more, but with every influx of people it showed up consistently error 503– the server’s patience has run out! The server couldn't load my blog.

Error 503
Each account on the server is allocated a certain amount processes that process user requests. Requests arrive at the server and are queued. Light requests are processed quickly, and heavy problematic ones are processed slowly, slowing down the progress of the queue. When the queue length reaches a certain value, the server stops accepting new requests, returning error 503 (Service Temporarily Unavailable, the service is temporarily unavailable)

People, stumbling upon a blank page, wrote and complained about the lack of availability of the promised information

For my part, I wrote to the hoster, asked, and cursed.

The hosting support service tried very hard to solve something, but everything was useless - my blog was rapidly falling to zero in searches. Search traffic in the fall could not be called traffic. Not traffic, but tears.

By December, our relationship with the support service had already smoothly flowed from constructive and tolerant to the stage of showdown: who is to blame and what to do. And somehow, in the midst of these showdowns, the thought came up that I had a lot of plugins installed (at that time there were 37 of them).

Now I also think that that's a lot. But on a regular shared hosting this was not felt at all! Therefore, at that moment I did not bring our disputes with the host to war and quickly returned the blog back to timeweb

But the idea sown borne fruit. Having dealt with the questions a little internal optimization and speed up the loading of the blog, I came to the conclusion that plugins are not always useful! For all their convenience.

They create additional queries to the database, additional load on the server and thereby slow down the engine. The speed of the already slow WordPress drops and the ubiquitous Google begins to hint that your blog is supposedly slower than others, and therefore give way in the search results to faster ones. And this is at best! In my case, he told me harshly and firmly:

Incl. the abandonment of plugins began as a necessary measure. New trends require new solutions. I had to look alternative solutions. WordPress without plugins!

To speed up WordPress to the maximum, it makes sense to delve into it and find a solution of the class: “both the wolves are fed and the sheep are safe” - preserve the usual functionality and do without plugins. Well, at least without most plugins.

Plugin is a small auxiliary program. It is designed to expand the functionality of the main program (in our case, WordPress), complementing it and improving it in certain areas. At the same time, the main program includes a plugin execution mechanism, that is, WordPress can work with auxiliary programs.

Pros of plugins

  1. Plugins can perform completely different functions - from solving simple problems to complex integrated solutions (forums, online commerce modules, etc.)
  2. Even a beginner can install them
  3. It is not necessary to understand PHP and CSS to enhance the functionality of the blog

Cons of plugins

  1. Excessive number of requests to the web server
  2. Database queries can be very heavy, placing increased load on the server
  3. The update time of the plugins may not coincide with the update of the engine itself and, as a result, stop working
  4. To block updates, beginners install additional plugins
  5. Not every hosting can support more than 50 plugins (in my case, it no longer behaved adequately with 37 plugins)
  6. When moving to a new hosting, unexpected problems may arise. Starting from banal reconfiguration of plugins, ending with conflicts and incompatibility, or even inoperability of individual plugins. Just the other day I had to solve a problem with the FacebookShare plugin for one partner - the encoding was not working correctly

To summarize, I can say that today I have abandoned most of the plugins, but my blog has not changed in terms of functionality in any way.

There are 14 active plugins on the Network Path, of which only 4 are standard and generally accepted. I think this is until I figure out how to replace them with a piece of code.

This is what now works great on my blog without plugins:

  1. Antispam in comments
  2. Site map
  3. Popular posts in the sidebar with pictures
  4. Similar entries under posts (with images displayed) - how PageSpeed ​​kept complaining about this plugin, its java scripts and css tables, even after optimization and compression, created quite a load
  5. bread crumbs
  6. Page navigation
  7. Top commentators
  8. Google+ recommendation buttons and

On home page, as well as on category pages, archives and search results, page navigation (also known as pagination) is usually needed. Blogs on WordPress are no exception; they also use pagination, when the results of the information output are divided into several pages.

Previously, to implement this feature, third-party plugins or special functions were used that were located in the file functions.php. However, with the release of WordPress version 4.1, the pagination feature was built into the core of the CMS, and now the internal functions of WordPress are enough to implement page navigation and there is no need to add third-party code or plugins.

I wrote earlier about a similar improvement on the part of WordPress regarding the TITLE tag - https://aboutwordpress.ru/post/wordpress-title/.

What is pagination

Pagination is the division of information into pages. This concept also means the sequential numbering of pages, indicated by numbers located at the bottom, top or side of the page.

WP-PageNavi - WordPress pagination plugin

The most popular pagination plugin for WordPress is WP-PageNavi. To be honest, it copes with the pagination task so well that there is no point in discussing and comparing other plugins.

WordPress pagination - WP-PageNavi plugin

WordPress pagination without plugin

In order to do pagination on a website without plugins, we will use the built-in WordPress function the_posts_pagination(). In the place we need, we need to insert the following code (usually these are files index.php, category.php and the like):

The result of the the_posts_pagination() function will be approximately the following HTML code:

Removing H2 Heading from Pagination

The H2 header “Post Navigation” immediately catches your eye. Which in most cases has no place on the site. To get rid of it, add the following code to the file functions.php:

/* Remove H2 from pagination */ add_filter("navigation_markup_template", "my_navigation_template", 10, 2); function my_navigation_template($template, $class)( return "

"; }

Setting up pagination pages

By default, the_posts_pagination() displays the first and last page, as well as one page around the current one. All others are replaced with an ellipsis. This behavior can be changed using arguments:

  • show_all - show all pages
  • end_size - number of pages at the beginning and end of the list
  • mid_size - number of pages to the left and right of the current page

For example like this:

2, "end_size" => 2,)); ?>

CSS Pagination Styles

Page-numbers ( padding: 1% 2%; box-shadow: 0 0 10px #ccc; margin: 0 1% 0 0; background: #fff; border-radius: 3px; )

Links to pagination pages with these styles will look like this:

Some webmasters would like to have their website on WordPress without a single plugin. For those who use a huge list of plugins, it must not be clear why this is necessary.

In fact, both groups of webmasters are right, and both are wrong, at the same time. WordPress without a plugin is entirely possible, but not entirely possible.

Let's consider this issue in more detail.

Why do you need WordPress without a plugin?

Every plugin on WordPress loads the server. Thus, every time the site is loaded, the hosting server receives a certain load, and this load increases with the number of plugins. The load will grow exponentially with the increase in visitors, because each person will load the server.

Without going into server details, let's say that many plugins slow down the site, and the slower it works, the more plugins, more visitors and weaker hosting. By the way, read how to find out how long it takes to load your site.

This is where the idea of ​​making WordPress without plugins comes from.

Is it possible to make WordPress without plugins?

Most of the functions that are reproduced on a WordPress website can be implemented without plugins. However, this is not as simple as it seems. To do it, for example, without a plugin, you will need to write the necessary code in the right place, the desired file. You don’t have to write this code and can easily find it on the Internet, but you will have to put it in the right place yourself. And if you make a mistake, then, at best, the function will not work. At worst, the entire site will not work. And then you will have to restore it. It’s good if you remember which file and where you made the changes. And if not, then you will have to do it from a backup.

In simple terms, making your own WordPress without a plugin requires knowledge and experience. But not everyone has them. And then, WordPress was created so that anyone could create a website on it, without special knowledge and experience.

WordPress without plugins will not be as functional, and it will not be as easy to configure this or that function. So, if you, for example, try to make a slider without a plugin, then to add and replace images in it, you will have to edit the code, and this should be done with all the attention and concentration. At a time when plugins for sliders allow you to not even think too much when editing a site element.

Do you need WordPress without plugins?

Having said the above, the answer is obvious - no, you don’t need to make WordPress without a plugin, at least completely. On one side of the scale is the load on the server, on the other are long hours of code editing. The choice is obvious. Moreover, if you use good hosting, you will not feel the load.

However, you can still try to implement some simple functions without a plugin on WordPress. This will allow you to gain invaluable experience.