Some learning methods about WordPress

First of all, WordPress is a foreign open source CMS.
It is some powerful, strong to I do not know how to describe it. It can almost complete all the types of websites you think of. This is no exaggeration, our team has used it to complete a single 6-digit project.
It’s some mighty, powerful and we do not know how to get close to it, familiar with it, learn and apply it. I have also light up the night war, Bing lamp candle. At the end, little success.
Below, I come to sum up my way to learn WordPress, I hope you can help, even if it is a little bit of guidance, but also excellent.
WordPress is a foreign CMS, there are almost all of its website abroad, I list a few I often go to the site.
Official website: https: //
Here on the latest information on the WordPress, the latest version of the program is also on the top of the starting.
Official documentation: https: //
Here on the side of WordPress latest, most accurate, the most complete, authentic description. Prior to this, this document is in Chinese version, but more than why, recently seems to have been canceled.
But I still recommend to see the original English, because it is the most accurate.
Official code reference: https: //
Here are examples of WordPress function, description, very detailed.
Take our most commonly used add_action function, its description is very detailed. Its address is: https: //
Here is a detailed description of the add_action function which parameters accepted, what is the type of parameters, what is the value of the return, which is the source of which documents, the first few lines. In the inside have a detailed description.
If you want to learn WordPress in depth, it is recommended that you look at this site, then you will find some wonderful things.
Official forum: https: //
Forums from the installation of the program to the plug-in development, from the theme template to a variety of troubleshooting has a very detailed partition. And this forum is very active.
PHP official website:
WordPress is based on the PHP language to develop, there is a better PHP basis to understand WordPress code, otherwise it is tantamount to look at the book.
Finally, I want to introduce you to a black technology! Technology! Technology! The is you are not wrong. Baidu localization, although doing a good job, but in the search for technical articles or when the difference is hundreds of kilometers. I found out all the reprint is not much to say ok! The The
It is very difficult for us to find a solution to the problem directly through the documentation before we have any problems before we are in contact with the problem.
At this time, we have to make use of the search. You may have problems before you have and you encounter the same problem people, they may be published on the Internet for help, may also have left a solution. Even if these are not, the search engine can also give you a solution to the problem.
Well, today, first wrote here, there is time to share with you to learn the method.
Yes, the top of the site may be due to some reasons can not be accessed, here to recommend a tool to the wall. Ladder VIP address is: https: //, everyone to buy their own use.

wordpress removes the wp-json link and the wp-embed.min.js file

Recently updated the latest version of the wordpress 4.4, update what function I do not know, I know I do not have access to, but found that there are several functions inside the link function, I do not have access. So we removed him, mainly more REST API (through the REST API can easily access the site’s data), wp-json link, embeds function (embeds function can allow more convenient reference to third-party resources) wp-embed.min.js file.
We do not have to load it to do what, but also affect the site to read the speed, then we talk about how to prohibit out.
First talk about the disabled REST API, remove the wp-json link method, add the following code to the theme functions.php file to disable the REST API and remove the head inside the output of the link information:

  1. add_filter(‘rest_enabled’, ‘_return_false’);
  2. add_filter(‘rest_jsonp_enabled’, ‘_return_false’);
  3. remove_action( ‘wp_head’, ‘rest_output_link_wp_head’, 10 );
  4. remove_action( ‘wp_head’, ‘wp_oembed_add_discovery_links’, 10 );

Disable embeds is actually more complex (code more), the official and even developed a plug-in for this, we can use the plug-in to disable: Disable Embeds, if you do not want to use plug-ins, then plug the code inside the copy to the theme functions.php File can be.

  1. function disable_emojis() {
  2. remove_action( ‘wp_head’, ‘print_emoji_detection_script’, 7 );
  3. remove_action( ‘admin_print_scripts’, ‘print_emoji_detection_script’ );
  4. remove_action( ‘wp_print_styles’, ‘print_emoji_styles’ );
  5. remove_action( ‘admin_print_styles’, ‘print_emoji_styles’ );
  6. remove_filter( ‘the_content_feed’, ‘wp_staticize_emoji’ );
  7. remove_filter( ‘comment_text_rss’, ‘wp_staticize_emoji’ );
  8. remove_filter( ‘wp_mail’, ‘wp_staticize_emoji_for_email’ );
  9. add_filter( ‘tiny_mce_plugins’, ‘disable_emojis_tinymce’ );
  10. }
  11. add_action( ‘init’, ‘disable_emojis’ );
  12. /** 
  13. * Filter function used to remove the tinymce emoji plugin. 
  14. */
  15. function disable_emojis_tinymce( $plugins ) {
  16. if ( is_array$plugins ) ) {
  17. return array_diff$pluginsarray( ‘wpemoji’ ) );
  18. else {
  19. return array();
  20. }
  21. }
  22. function disable_embeds_init() {
  23. global $wp;
  24. $wp->public_query_vars = array_diff$wp->public_query_vars, array( ’embed’, ) );
  25. remove_action( ‘rest_api_init’, ‘wp_oembed_register_route’ );
  26. add_filter( ’embed_oembed_discover’, ‘__return_false’ );
  27. remove_filter( ‘oembed_dataparse’, ‘wp_filter_oembed_result’, 10 );
  28. remove_action( ‘wp_head’, ‘wp_oembed_add_discovery_links’ );
  29. remove_action( ‘wp_head’, ‘wp_oembed_add_host_js’ );
  30. add_filter( ‘tiny_mce_plugins’, ‘disable_embeds_tiny_mce_plugin’ );
  31. add_filter( ‘rewrite_rules_array’, ‘disable_embeds_rewrites’ ); }
  32. add_action( ‘init’, ‘disable_embeds_init’, 9999 );
  33. function disable_embeds_tiny_mce_plugin( $plugins ) { return array_diff$pluginsarray( ‘wpembed’ ) ); }
  34. function disable_embeds_rewrites( $rules ) { foreach ( $rules as $rule => $rewrite ) { if ( false !== strpos$rewrite, ’embed=true’ ) ) { unset( $rules$rule ] ); } }
  35. return $rules; }
  36. function disable_embeds_remove_rewrite_rules() { add_filter( ‘rewrite_rules_array’, ‘disable_embeds_rewrites’ ); flush_rewrite_rules(); }
  37. register_activation_hook( __FILE__, ‘disable_embeds_remove_rewrite_rules’ );
  38. function disable_embeds_flush_rewrite_rules() { remove_filter( ‘rewrite_rules_array’, ‘disable_embeds_rewrites’ ); flush_rewrite_rules(); }
  39. register_deactivation_hook( __FILE__, ‘disable_embeds_flush_rewrite_rules’ );

Every time you update the wordpress version will be more things, such as the previous emoji, and are input on the page content, more or less will affect the speed, our blog is basically updated under the article, engage in too much responsibility for the excessive, Not to get rid of REST API and embeds, for the user experience, so that the website faster display of our code on the OK.

WordPress front end user center often used data and access methods

In the development of ordinary WordPress theme, we have ready-made theme can refer to, but the development of WordPress front-end user center, we are not easy to find a reference, probably because WordPress front-end user center needs no common theme The This article will introduce some of the development of WordPress front-end user center users often to some data acquisition method.

Global variables:

  1. $authordata
  2. $post
  3. $wp_query

Get the author archive page link

  1. echo get_author_posts_url( $authordata->ID );

Get the author’s nickname

  1. echo esc_attr( $authordata ->display_name )

Get the number of comments, use in loop:

  1. echo $post->comment_count

Get comment link, loop use:

  1. comments_link()

Get the current login user information

  1. $current_user = wp_get_current_user();

Gets the user information that needs to be operated

  1. global $wp_query;
  2. $author = $wp_query->get_queried_object();

Above is the development of front-end user center wordpress time often used in some of the data acquisition method, of course, this is only part of which I will be in the development of front-end user center when the accumulation gradually added for your reference.

Code to achieve WordPress automatic keywords keywords and description

The following code to achieve the label as a keyword; to summary for the description, if not fill out the abstract, then automatically intercept the article before the 200 words for the description. (Tutorial transferred from: DeveWork)

Code to achieve WordPress automatic keywords and description:
The following code put under your theme funtions.php the last one?

// Automatic keywords and description
function get_cats_name () {
$ allcats = get_categories ();
foreach ($ allcats as $ category)
$ keywords [] = $ category-> cat_name;
return $ keywords;
// utf8 substr
function utf8Substr ($ str, $ from, $ len) {
return preg_replace (‘# ^ (?: [x00-x7F] | [xC0-xFF] [x80-xBF] +) {0,’. $ from. ‘}’.
(): [x00-x7F] | [xC0-xFF] [x80-xBF] +) {0, ‘. $ len.’}). * # s’
‘$ 1’, $ str);
// Meta SEO
function meta_SEO () {
global $ post;
$ output = ”;
if (is_single ()) {// if it is an article page
$ keywords = ”;
$ description = ”;
if ($ post-> post_excerpt) {// If the article abstract exists on the article summary to describe
$ description = $ post-> post_excerpt;
$ description = str_replace (“rn”, “”, $ description);
$ description = str_replace (“n”, “”, $ description);
$ description = str_replace (“” “,” ‘”, $ description);
$ description. = ‘…’;
} else {// If the article summary does not exist, truncate the article before the 200 words for the description
$ description = utf8Substr (strip_tags ($ post-> post_content), 0,200);
$ description = str_replace (“rn”, “”, $ description);
$ description = str_replace (“n”, “”, $ description);
$ description = str_replace (“” “,” ‘”, $ description);
$ description. = ‘…’;
$ tags = wp_get_post_tags ($ post-> ID); // take the article tag
foreach ($ tags as $ tag) {
$ keywordarray [] = $ tag-> name;
// Use the article tag as a keyword
$ keywords = implode (‘,’, array_unique ((array) $ keywordarray));
} else {// if it is not an article page
$press = ‘wordpress, wordpress theme, wordpress tutorial, wordpress theme download, wordpress blog theme, wordpress corporate theme, wordpress theme custom’; // quotation marks between your blog keywords,
$ description = ‘theme cat, dedicated to the majority of users to provide the latest and most complete wordpress theme’; / / quotation marks between your blog to write a simple description, do not over 200 words
// Output keywords
$ output. = ‘<meta name = “keywords” content = “‘. $ keywords. ‘” />’.
$ output. = ‘<meta name = “description” content = “‘. $ description. ‘” />’.
// output description
echo “$ outputn”;
add_action (‘wp_head’, ‘meta_SEO’); // add the meta_SEO function to the header

The contents of lines 43 and 44 need to be modified according to your website.

Prohibit wordpress4.4 + version automatically generates a 768 pixel thumbnail

4.4 version later, wordpress added a responsive picture function, the purpose is to allow the picture to adapt to the phone, tablet and other different screens, you upload the picture will automatically generate a 768 pixel thumbnail, but I do not want this feature, the Thumbnail size is fully adjusted to 0, prohibit wordpress automatically generate thumbnails, upload pictures or will generate a 768 pixel thumbnails.

This problem I find a long time did not find a solution to study the day, finally resolved.
In the document wp-admin \ includes \ schema.php Lane in the following code, you can see is 4.4 new features.

  1. // 4.4.0
  2.     ‘medium_large_size_w’ => 768,
  3.     ‘medium_large_size_h’ => 0,

This is the default option to install wordpress, but there is no place to change in the background, there is no change code, because it has been deposited into the database, so go into the database.
Enter the command to change the value of medium_large_size_w to 0 on the line
SQL commands are as follows:

  1. SELECT * FROM `wp_options` where option_name=’medium_large_size_w’

Prohibit wordpress generation 768 pixel thumbnails can effectively save the site space, especially those pictures of many sites (such as the theme of the cat wordpres theme download station) need to prohibit this thumbnail.

WordPress links are automatically added Noopener Noreferrer

I do not know if there is no need to put the chain in the article, taking into account the problem of SEO will generally give the site an article outside the chain automatically nofollow function, nofollow is an HTML tag attribute value. The meaning of this tag is to tell the search engine “Do not follow the links on this page or do not track this particular link.
Beard recently in the editorial website when the article found outside the chain can not automatically add nofollow attribute, after some research is the new version of the wordpress problem.
WordPress automatically adds the new Noopener Noreferrer attribute (resulting in the nofollow property failure) for all links that require a new window in the most recent version update.
Noopener Noreferrer property is not a new release standard, but v4.7.4 version of the WordPress editor will add the default by default.
This property is mainly used to prevent new windows from opening links when there may be phishing attacks, so as a security content WordPress gives added.
But after the addition of the new tab page will not be able to follow the conventional method to track the source page, which in the attribute field has been able to see: No Refer.
After the upgrade to WordPress v4.7.4 version of the original release of the contents of the new window link does not automatically add Noopener Noreferrer.
But if it is a new article or you modify the contents of the previous release, then the new window link will add Noopener Noreferrer.

Please add this code to the bottom of your wordpress theme at function.php and save and upload it

  1. //WordPress links auto add Noopener Noreferrer
  2. add_filter(‘tiny_mce_before_init’,’tinymce_allow_unsafe_link_target’);
  3. function tinymce_allow_unsafe_link_target( $mceInit ) {
  4. $mceInit[‘allow_unsafe_link_target’]=true;
  5. return $mceInit;
  6. }

Add the newly released content after the link if set to a new window open then the Noopener Noreferrer property will no longer be added automatically.
If the previously published article has been attached to the property even after the addition will not automatically remove, you need to manually edit and then delete the new attribute.
That is, manually edit the article and switch the editor to text mode and then rel = “noopener noreferrer” deleted and then save the update on the line.

WordPress website on the line before you have to complete these five things

In the site of the user exchange group which chat, found that many people always ask a question: the site before the line, what needs to be done? I think this question makes sense. According to past experience to sum up, share the theme of the cat’s friends.
Each site may have its own differences, but there are a lot in common. For the WordPress site, before you go online, you should complete the following five things:

1. prohibit search engine index.
This is because when you just started building the site, it is not suitable for search engine content included. At this time, the site content has not yet been built, some text is only some of the presentation. If the search engine contains the content, it is terrible, because the user to see such a content will have a bad impression on your site. You can in the WordPress management background [settings] -> [read] page settings: shielding search engine index site content. Of course, after everything is ready for the site, do not forget to modify the settings here, allowing the search engine to index the site content.

2. Check the website link.
Make sure that all links within the site are working properly. If the site has a failed link, it will affect the site’s SEO ranking. We have a few days ago to recommend you Broken Link Checker free plug-in, can help you complete this work. (To the bottom of this article)

3. Modify the thumbnail size.
When you change the WordPress theme to the site, it’s important to modify the thumbnail size because the thumbnails of many topics are not the same size.


4. Check the contents of the website twice.
Including the sidebar of the site, footer area, and navigation bar. We often leave some text errors, especially when you stare at the same site content text for a week, so please check it carefully.

5. View the website with your phone.
If conditions permit, try to check the appearance of your website with a variety of different mobile phones and Internet devices. Otherwise, if you only have a large screen PC, you can also try to continuously reduce the width of the browser to see the appearance of the site in different sizes.
If you have any special experience, welcome to communicate with us through the message.

How to modify the name of the WordPress default role

WordPress provides five default roles, different roles have different permissions, decide what they can and can not do; for example: whether the right to write or review other people’s articles; whether the right to replace the site theme. However, WordPress does not allow you to directly modify the default role name. However, it is not difficult to do it, the theme cat today will tell you how to modify these default roles.
WordPress default 5 roles are: Admin, Editor, Author, Contributor, Contributor, Subscriber.

Why do I need to customize the role name?
For users who use WordPress to build a personal blog, there is no need to modify these role names, because he generally does not use these. But for the corporate website is necessary.
WordPress after the acquisition of WooCommerce, the use of WordPress to build foreign trade sites and online mall users will be further increased. If you use WordPress to help customers to do an e-commerce site, site visitors (that is, potential customers) will be very strange, why their identity is Subscriber (subscribers)? Therefore, this time must deal with this problem.
To modify the default role of WordPress, you only need to write down the code to copy the functions.php file or the site-specific plugin for the theme you are using:

  1. function wps_change_role_name() {
  2.   global $wp_roles;
  3.   if ( ! isset( $wp_roles ) )
  4.    $wp_roles = new WP_Roles();
  5.   $wp_roles->roles[‘contributor’][‘name’] = ‘Owner’;
  6.   $wp_roles->role_names[‘contributor’] = ‘Owner’;
  7. }
  8. add_action(‘init’, ‘wps_change_role_name’);

The name of the Contributor role is changed to Owner (owner, owner). Here you can also use the Chinese, but must remember to save the file as utf8 no bom format, otherwise the Chinese may be displayed as garbled.
This code comes from Kevin Chard’s website. And then look back at the role of the site, turned into this:

However, it should be noted that this code is only the name of the Contributor role modified, and will not modify the corresponding permissions, nor add a new role, and even the role of slug (abbreviation, alias) will not modify.

No plug-in WordPress15 practical tips (1)

The power of WordPress is that you can use plug-ins to easily extend the functionality of your site. But sometimes, we need to modify or add the function, just a few lines of code can be done. Today, the theme cat will give you 15 very practical WordPress skills, and do not need any WordPress plugin.
In the WordPress official plugin directory, there are about 40,000 free WordPress plugins that can extend WordPress functionality. In addition, there are many can not count the number of charge plugins. Through these plug-ins, basically can meet the needs of the vast majority of the site.
But sometimes we need some of the features, no need to plug the same can be done. Below, we will give you some very useful WordPress skills, tips, tips, no need to install any WordPress plugin.
This article is longer, divided into two release. This article is the first chapter, the next article will be released within a week:

WordPress Code Tuning: Administrator and Manage Background (Console, Dashboard)
1. Modify the Logo (logo) in the WordPress website login interface
First introduce a technique related to website branding: If you plan to modify your website (or your client’s website) login interface in the WordPress Logo, the following code is just right for you. Use it very simply, just copy the following code into the funcitons.php file on your site’s theme, or in a plugin dedicated to your site:

  1. function my_custom_login_logo() {
  2.     echo ‘&lt;style type=&quot;text/css&quot;&gt;
  3.         h1 a { background-image:url(‘.get_bloginfo(‘template_directory’).’/images/custom-login-logo.png) !important; }
  4.     &lt;/style&gt;’;
  5. }
  6. add_action(‘login_head’, ‘my_custom_login_logo’);

And then do their own Logo, named custom-login-logo.png, upload to the use of the theme directory within the images folder. This code we introduced, but also introduced how to modify the default Logo corresponding to the URL.

2. Modify the Logo of the WordPress management background (dashboard)
Want a WordPress site to stay closer to your business, feel more cordial? Replace WordPress management background (console, dashboard) in the upper left corner of the default WordPress Logo it. Many plugins can do this, but the following code can also directly achieve this function. Similarly, copy the following code into the theme’s funcitons.php file, or in the theme-specific plugin:

  1. function custom_admin_logo() {
  2.   echo ‘&lt;style type=&quot;text/css&quot;&gt;
  3.           #header-logo { background-image: url(‘.get_bloginfo(‘template_directory’).’/images/admin_logo.png) !important; }
  4.         &lt;/style&gt;’;
  5. }
  6. add_action(‘admin_head’, ‘custom_admin_logo’);

Then, you want to use the WP management background in the logo named admin_logo.png, uploaded to the use of the theme directory within the images folder.

3. Close the WordPress login box prompt function
To ensure the security of the WordPress site, it is important that we have written many articles on how to enhance the security of the site. We introduced this technique, but it is a very simple step, but also very useful. The default emptied, when you want to enter the account information log WordPress background, if you enter the information is wrong, WordPress will tell you the error message: the user name does not exist, or password error. This trick is to turn off such tips to enhance the security of the WordPress site.
To disable WordPress login error message, you need to copy the following code into the theme of the funcitons.php file, or within the site-specific plugin:

  1. function no_wordpress_errors(){
  2.   return ‘GET OFF MY LAWN !! RIGHT NOW !!’;
  3. }
  4. add_filter( ‘login_errors’, ‘no_wordpress_errors’ );

In this way, WordPress no longer outputs valid hints that can reduce the likelihood that the site will be compromised.

4. Keep the WordPress login status longer
If you are using WiFi or other wireless network, or use the public computer when the Internet, log on any one site, we must remember to withdraw in time. However, if you at home or company, use their own computer, after a while will be kicked out by WordPress, need to re-login, then it is also very annoying. At this time, you can try this technique to extend the retention time of WordPress login status. Likewise, copy the code into the funcitons.php file or in a site-specific plugin:

  1. add_filter( ‘auth_cookie_expiration’, ‘stay_logged_in_for_1_year’ );
  2. function stay_logged_in_for_1_year( $expire ) {
  3.   return 31556926; // 1 year in seconds
  4. }

By default, if you select the “Remember Me” option when you log in to WordPress, WordPress will remain logged in for 2 weeks. In the above code, we set it to 1 year.

5. Replace “Hello” with “Login as …” in the WordPress toolbar
If you think WordPress at the top of the menu toolbar, the default “Hello” is not suitable for formal occasions, or you want to change a welcome message, please copy the following code to functions.php file, or on the website dedicated plug-in:

  1. function replace_howdy( $wp_admin_bar ) {
  2.     $my_account=$wp_admin_bar-&gt;get_node(‘my-account’);
  3.     $newtitle = str_replace( ‘Howdy,’, ‘Logged in as‘, $my_account-&gt;title );
  4.     $wp_admin_bar-&gt;add_node( array(
  5.         ‘id’ =&gt; ‘my-account’,
  6.         ‘title’ =&gt; $newtitle,
  7.     ) );
  8. }
  9. add_filter( ‘admin_bar_menu’, ‘replace_howdy’,25 );

In the third line of the above code, the $ newtitle parameter can set the desired greeting. If you want to use Chinese here, please remember to save the file as UTF8 no BOM format.

6. Modify WordPress to manage the background footer text
Brand promotion is to convey information and consistent. So if you create a website for your customers, what you want to do for yourself makes your customers happy and very important to them. Therefore, in addition to changing the login page and management background of the upper left corner of the Logo, you can also manage the background part of the background to add the customer’s slogan (corporate values, vision, etc.) or other interesting text.
Cool! Place the following code in the funcitons.php file, or within the site-specific plugin:

  1. function remove_footer_admin () {
  2.   echo &quot;Your own text&quot;;
  3. }
  4. add_filter(‘admin_footer_text’, ‘remove_footer_admin’);

Now, you can add some here to give people a deep impression on the text, or quote some inspirational, connotation of the text, on the echo that line in the double quotation marks on it


7. Add short code to the gadget (pendant)
Short code (shorcode, also translated as “short code”, “short code”, etc.) super useful, because they only need a pair of square brackets, you can replace the original very long code snippet. By default, WordPress Widget (pendant, gadget) does not support short code, can only speak short code as ordinary word processing. However, you can simply use the following code in the functions.php file for the theme you are using, or within the site-specific plugin, you can use the short code in the gadget:

  1. define(‘widget_text’, ‘do_shortcode’);

In this way, you can use short code in Widgets (gadgets).


How to reset the WordPress database

There are always WordPress novice in the theme of the cat’s QQ user group asked this question: how to clear WordPress website data ah? How to restore the wordpress website to the initial state? The simpler rude solution is to empty the database and reinstall it. But today the theme cat to give you recommend a more simple way.
Even skilled use of WordPrss master, there will be such a demand: for example, sometimes need to test the new wordpress theme or plug-in, to delete all the contents of the wordpress site; or want to empty the site content, re-do a new blog.
Before we encounter this problem, we will delete the existing installation (mainly empty or delete the database, etc.); then re-install WordPress. But this is still a bit cumbersome, especially for users who are not familiar with the operation of the database. Now, the theme cat gives you a wordpress plugin that lets you easily reset the WordPress site.

WordPress Database Reset plugin
WordPress Database Reset, meaning “WordPress database reset”, is a free plug-in from WordPress official plug-in directory, you can restore the WordPress database to the default state. Since the various settings of the WordPress site are stored in the database, this also means that all content of the site will be erased and the site will be restored to the initial installation state.
The wordpress plugin is very easy to use, install and enable the plug-in, in the management of the background sidebar management options, find the “Tools (Tools) -” [database reset (Database Reset)].

Here, you can choose to empty a single table (table), such as delete all comments, delete all pages, etc .; you can also choose to empty all the tables.
Next, enter the plugin generated string, in this case s42Uz, and then click the [Reset Database] button. Then, the plugin will revert to WordPress initial settings and bring you back to the admin background home page.
The plugin will not delete or change your files, such as your uploaded images. It only removes custom options and content, including pages, articles and comments, and so on. However, if you want to reset the important site, in order to prevent mistakes, be sure to do a good job backup.

WordPress development tutorial: the original ecology of the wordpress ajax

Recently small V (site friends) in the development of an adaptive wordpress blog theme, the wordpress theme of a large number of data display and submission are used ajax technology, so small V specially written a tutorial record, to facilitate other wordpress developers do wordpress ajax application development time to do reference. If some small partners do not know what is ajax, please Baidu Baidu ~ ~, gossip is not to say, the tutorial began.
Many developers in the write plug-in like the following way to achieve ajax:

  1. require_once( ‘../../../../wp-config.php’ );

Even the Baidu webmaster platform official development of the wordpress structured data submitted plug-in is also the realization of ajax, which is a very irrational wording, because once the user set the directory is different, the relative path will be invalid. And if you Your plugin is using object-oriented writing, you will not be able to directly use some variables and private methods. The biggest drawback is that will lead to the entire WordPress framework to reload again, seriously affecting the efficiency of the site.
In fact, wordpress in order to facilitate the development of developers with ajax function plug-in theme has been pre-defined ajax method, we only need to use the official reservation method to use just fine. In the development of wordpress ajax you first understand that, whether it is the background or foreground any Ajax requests are in admin-ajax.php deal, send a request to admin-ajax.php, there is a required parameter is $ _REQUEST [‘action’] because admin-ajax.php needs to trigger different hooks depending on whether the user is logged in.

  1. if ( is_user_logged_in() ) {
  2.     /**
  3.      * Fires authenticated AJAX actions for logged-in users.
  4.      *
  5.      * The dynamic portion of the hook name, `$_REQUEST[‘action’]`,
  6.      * refers to the name of the AJAX action callback being fired.
  7.      *
  8.      * @since 2.1.0
  9.      */
  10.     do_action( ‘wp_ajax_’ . $_REQUEST[‘action’] );
  11. else {
  12.     /**
  13.      * Fires non-authenticated AJAX actions for logged-out users.
  14.      *
  15.      * The dynamic portion of the hook name, `$_REQUEST[‘action’]`,
  16.      * refers to the name of the AJAX action callback being fired.
  17.      *
  18.      * @since 2.8.0
  19.      */
  20.     do_action( ‘wp_ajax_nopriv_’ . $_REQUEST[‘action’] );
  21. }

The above code from the wordpress system file admin-ajax.php, from the above code we can see that we want to initiate a request first to know whether this request is initiated in the login state? Different state trigger hook is not the same, the following is a theme in the use of jquery achieve ajax example code:

  1. add_action (‘wp_head’, ‘v7v3AjaxScript’);
    function v7v3AjaxScript () {
    print ‘<script> var v7v3_ajaxurl = “‘. admin_url (‘admin-ajax.php’). ‘”‘. “; </ script> n”;
    print “<script>
    $ (docunment) .ready (function () {
    $ .ajax ({
    url: v7v3_ajaxurl,
    data: {
    action: ‘is_login’
    type: ‘post’,
    cache: false,
    success: function (data) {
    alert (data);
    </ scrip> “;

    add_action (‘wp_ajax_nopriv_is_login’, ‘v7v3_ajax_not_login’);
    add_action (‘wp_ajax_is_login’, ‘v7v3_ajax_is_login’);

    function v7v3_ajax_is_login () {
    global $ current_user;
    get_currentuserinfo ();
    printf (‘Login User Hello:% s!’, $ current_user-> display_name);
    / / Die before the end of the die or exit is very important, we must add.

    function v7v3_ajax_not_login () {
    print ‘Dear Visitors Hello! ‘;
    / / Die before the end of the die or exit is very important, we must add.

In the development of wordpress ajax application is the most important point before the end of the function must be added die or exit, if not add the wordpress framework will be reloaded again.

WordPress editor shortcuts – make writing more convenient

Occasionally seen on DeveWork, so reproduced to the wordpress theme download station. This is the default editor of the shortcut keys, but also very easy to remember, with this, you can more convenient to write.

Bold text: Ctrl + B
Text Italic: Ctrl + I
Text strikethrough: Alt + Shift + D
Underline: Ctrl + U
List of non-serial numbers: Alt + Shift + U
Serial number list: Alt + Shift + O
Quotation: Alt + Shift + Q
Left Alignment: Alt + Shift + L
Center: Alt + Shift + C
Right-aligned: Alt + Shift + R
Align at both ends: Alt + Shift + J
Insert the edit link: Alt + Shift + A
Delete the link: Alt + Shift + S
Insert multimedia: Alt + Shift + M
More tags: Alt + Shift + T
Next tab and post article: Alt + Shift + P
Switch spelling checker status: Alt + Shift + N
Full screen mode: Alt + Shift + G
Show / hide advanced features: Alt + Shift + Z
First level title: Ctrl + 1
Secondary title: Ctrl + 2
Level 3 Title: Ctrl +3
Level 4 Title: Ctrl +4
Level 5 Title: Ctrl +5
Six title: Ctrl +6
Paragraph: Ctrl + 7
Insert Div: Ctrl + 8
Address: Ctrl + 9
Select all: Ctrl + A
Cut: Ctrl + X
Copy: Ctrl + C
Paste: Ctrl + V
Undo: Ctrl + Z
Redo: Ctrl + Y
Insert line: Shift + Enter
HTML and visual mode switch: Alt + Shift + E
Help: Alt + Shift + H
Full-screen mode editor width:
Wider: Alt +
Narrower: Alt –
Default: Alt 0

How to limit the length of WordPress messages

WordPress message function (comment function), can encourage users to discuss the contents of the article to discuss the exchange. However, for some serious sites, the message is too long or too short, and is not conducive to communication. In this article, we will show you how to limit the length of WordPress comment message, both to prevent the message content is too short, but also to prevent the message content is too long.

Why limit the length of WordPress comments?
For some of the sites often discussed around a topic, the contents of the comments will be limited to a certain range, but more conducive to discussion, such as comments limited to more than 20 words, 1000 words or less. If someone commented only to write a word, such as “praise”, in fact, not much of a sense. This situation is more like to take links to spam comments. Likewise, if someone’s comments are over 1000 words, the scope of the discussion is largely beyond the scope of an article if it is not made with a lot of spam links. Therefore, by limiting the length of WordPress messages, you can better improve the discussion atmosphere of such sites.

Method 1: Use plugins to limit WordPress message length using plugins is relatively simple
In the WordPress management background, in the [plug-in] -> [install plug-in] page, search Control Comment Length; and then download and activate Control Comment Length plug-in.
Then, in the [Settings] -> [Control Comment Length] page to configure. This is a German plugin, I do not know, but fortunately the interface also includes English translation. In order to facilitate the understanding, I added the Chinese translation in the following figure.

Need to fill in, including the minimum number of words and the maximum number of words, and the message length beyond the limits of the prompt message. Limit the number of words, you can set according to their own website situation. Where the unit is byte, UTF8 encoding in each Chinese characters accounted for 3 bytes, English letters and numbers accounted for 1 byte; so we recommend that you set to 60 and 3000 respectively. If you only want to limit the maximum number of words, you only need to limit the minimum number of words to 1; Similarly, if you only want to limit the minimum number of words, you only need to set the maximum number of words to a large number (such as 99999) can be.
Prompt information content can be set up their own. The contents of the above are German, you should at least replace the same with your WordPress site front language. The message can contain HTML code, so you can define the contents and format of the output prompt. Note that there are three parameters: {CommentLength}, representing the length of the message; {minimalCommentLength}, the minimum number of bytes; {maximalCommentLength}, the maximum number of bytes.

Method 2: Limit WordPress Message Length by Code
If you do not want to use plug-ins, more willing to use code to solve the problem, this approach is more suitable for you. You only need to copy the following code to your wordpress theme funcitons.php file, or put your site dedicated plug-in, you can.

  1. add_filter( ‘preprocess_comment’, ‘wpb_preprocess_comment’ );
  2. function wpb_preprocess_comment($comment) {
  3.     if ( strlen$comment[‘comment_content’] ) > 3000 ) {
  4.         wp_die(‘Comment is too long. Please keep your comment under 3000 characters.’);
  5.     }
  6. if ( strlen$comment[‘comment_content’] ) < 60 ) {
  7.         wp_die(‘Comment is too short. Please use at least 60 characters.’);
  8.     }
  9.     return $comment;
  10. }

It is important to note that the wp_die () function’s quotation marks are messages that are output when the message limit is exceeded, and you can replace it with Chinese (or your site’s corresponding front language). It is important to note that if you want to output Chinese prompts, please remember to save the functions.php file or the website-specific plug-in file as utf8 no bom format to prevent the output garbled; use notepad ++ free editor or everedit charging editor The There is one, each character accounted for 3 bytes, do not forget to convert Oh!

WordPress program in the win and Linux system under the pseudo static settings

Today, this article I came to tell you about the wordpress program in the win and Linux system under the pseudo-static set method.
The first: win system under the wordpress program pseudo static.
wordpress in the win system under the pseudo-static premise is the need for space system to support pseudo-static settings, and we also know that the general win system supports pseudo-static rules for the httpd.ini format, then we first first create a text document, the following code Copy and paste in the inside (this is what I have so far collected the most perfect win system pseudo-static rules).
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpd.ini and httpd.parse.errors files
# from access through HTTP
# wordpress pseudo static rules
# For tag (Chinese label and label page rules)
RewriteRule /tag/(.*)/page/(d+)$ /index.php?tag=$1&paged=$2
RewriteRule /tag/(.+)$ /index.php?tag=$1
# For category (Chinese classification and classification of the rules)
RewriteRule /category/(.*)/page/(d+)$/index.php?category_name=$1&paged=$2
RewriteRule /category/(.*) /index.php?category_name=$1
# For sitemapxml
RewriteRule /sitemap.xml /sitemap.xml [L]
RewriteRule /sitemap.html /sitemap.html [L]
RewriteRule /sitemap_baidu.xml /sitemap_baidu.xml [L]
RewriteRule /favicon.ico /favicon.ico [L]
# For file-based wordpress content (ie theme), admin, etc.
RewriteRule /wp-(.*) / wp- $ 1 [L]
# For normal wordpress content, via index.php
RewriteRule ^ / $ /index.php [L]
RewriteRule / (.*) /index.php/$1 [L]
Copy and paste the above code into the text document, we will save the text as httpd.ini, so that our pseudo-static rules on the well, we only need to upload this file to the space more directory, if in the background → fixed link selection Custom link input / %category%/%post_id%.html or / %post_id%.html click to save on it, which we also need a plug-in support, that is, to remove the category URL in the middle of the category, we only need In the background plug-in → install plug-in that search WP No Category Base, the installation is enabled on it. So we win system under the wordpress program pseudo static to complete.
The second: pseudo-static settings under Linux system
This is very simple, we know that the Linux system itself is the most perfect system using wordpress, its pseudo-static settings are very simple, we only need in the background → fixed link select custom link input /% category% /% post_id% .html or / %post_id%.html click Save on it. Similarly, it is also necessary to cooperate with WP No Category Base plug-in, the following I will support the Linux system. Htaccess pseudo-static rules to write out. The code is as follows:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^ index.php $ – [L]
RewriteCond% {REQUEST_FILENAME}! -f
RewriteCond% {REQUEST_FILENAME}! -d
RewriteRule. /index.php [L]
</ IfModule>
# END WordPress
The above code is the same, we need to create a new text document, and then paste the code into the paste, click Save as. Htaccess file, and then upload this file to the root of the space to complete.
This article is written here, and hope that those who use the wordpress program do not know how to set up a friend how to do some help, if you do not understand what, you can leave a message to me, thank you!

To all the wordpress novice, how to detect download the wordpress theme plugin contains the back door

Recently a lot of small partners have been discussing the site was black and download the free wordpress theme plugin hanging horse topic, then today V to teach you how to identify the wordpress theme plug is left behind the door. First of all, under the wordpress operating environment, I believe that a little bit of common sense of the owners know that wordpress is a run on the php + mysql system built on top of the system, and wordpress theme plug-ins are written as. Php suffix executable file this Is why wordpress’s free theme plugin is easy to stay behind the door problem. Since it is written by php, then we just know that the general use of PHP backdoor procedures can be a certain degree of awareness of the theme plug-in whether there is a backdoor Trojans, the following small V lists some common php backdoor function:
Execute system commands: system, passthru, shell_exec, exec, popen, proc_open (high risk)
Code execution: eval, assert, preg_replace (‘/ $ pattern / e’) (high risk)
File operations: file_get_contents, file_put_contents, fputs, fwrite (high-risk)
String encryption and decryption compression decompression hidden: base64_decode, gzinflate, gzuncompress, gzdecode, str_rot13, base64_decode, gzcompress, chr (suspicious)
wordpress Create backdoor user: wp_create_user, WP_User, set_role (high risk)
If the subject of small V mark the high-risk code can basically determine this theme is very problematic, and basically are to stay back door or do little tricks. If it is found in this article marked suspicious code that should be noted that the code is likely to encrypt the part of the back door. Many small partners certainly do not understand preg_replace (‘/ $ pattern / e’) What is the meaning of this code, the following small V to explain to you, preg_replace function using e modifier after the implementation of the reverse reference replacement will be replaced Of the code as php code to run, so it is also a very common backdoor code. In the detection of the theme plug contains the back door as long as the text search tool or software search theme plug-in php file contains the above keywords, in the search for preg_replace need to manually compare the code to see whether the inclusion of e modifier, if the subject file (5) .chr (3) .chr (58) This kind of code should be careful, and found that the subject file appears a lot of random characters have to be careful are generally encrypted code is likely to hide The back door.
PS: Because the usual beard finishing the theme and plug-ins are more, it is difficult to check all the documents are submitted side. Up to check the next few key files are hanging horse, so please download the theme as much as possible after their own check again.