By default, WordPress automatically converts the half-width symbol of the code into a full-width symbol to prevent external source code from being executed on the webpage. For example, it will replace -- -. When the code highlight plug-in is not used, the code directly pasted on the webpage cannot be used directly. You must change the symbol to a half-width corner. For friends who often need to use code in articles, the default conversion function of WordPress can be disabled.
Method 1
Modify the functions. php file of the current topic, for example, wp-content/themes/amazinggrace/functions. php, in <? Php and?> Add the following code between them:
The code is as follows: |
Copy code |
Remove_filter ('The _ content', 'wptexturize '); |
The advantage of this method is to directly modify the files in the topic package, so we can freely upgrade wordpress without changing the topic. Similarly, the disadvantage is that, after we change the topic, we need to re-add the code.
Method 2
Modify wordpress source file
The advantage of this method is that changing any theme without the wordpress version will not affect our modification. The disadvantage is that after the wordpress version is upgraded, you need to repeat this method and modify it again.
Practice: first open the wp-nodes des directory under the wordpress root directory, find the formatting. Php file under this directory, open the formatting. Php file, and find the following code:
The code is as follows: |
Copy code |
// Static strings $ Curl = str_replace ($ static_characters, $ static_replacements, $ curl ); // Regular expressions $ Curl = preg_replace ($ dynamic_characters, $ dynamic_replacements, $ curl ); |
Comment out all the codes of the two sentences, for example, the modified form is as follows:
The code is as follows: |
Copy code |
/* Why is the whole segment commented out? If we want to restore it, we only need to remove the annotator at both ends. Of course, you can also use // to comment out a single line Also, you can delete the code, but it cannot be recovered in the future. Therefore, it is best to comment out the code. Zi Han interactive visual sorting, reprinted please keep the original link, thank you for your cooperation // Static strings $ Curl = str_replace ($ static_characters, $ static_replacements, $ curl ); // Regular expressions $ Curl = preg_replace ($ dynamic_characters, $ dynamic_replacements, $ curl ); */ |
Method 3,Add the following code to the topic file functions. php to save the trouble of re-modifying wordpress during the upgrade.
The code is as follows: |
Copy code |
// Disable halfwidth to fullwidth $ Qmr_work_tags = array ( 'The _ title', // title 'The _ content', // content * 'The _ excerpt ', // Summary * 'Single _ post_title ', // The title of a single article 'Comment _ author', // comment author 'Comment _ text', // comment * 'Link _ description', // The URL description (which has been deprecated but is often used) 'Bloginfo', // blog information 'WP _ title', // website title 'Term _ description', // project description 'Category _ description', // category description 'Widget _ title', // The title of the widget. 'Widget _ text' // widget text ); Foreach ($ qmr_work_tags as $ qmr_work_tag ){ Remove_filter ($ qmr_work_tag, 'wptexturize '); } |