How to make WordPress theme code static? The following article will share with you the tutorial on staticizing WordPress theme code. I hope it will be helpful to you!
The so-called staticization of WordPress theme code is to replace the dynamic code in the WordPress theme with static content. Maybe you don’t know what dynamic code is, so think about it first. Question: Why does the same WordPress theme display the title "Pandou Blog" when used on my blog, but displays another title when used on your blog? The answer lies in the dynamic code in the theme, which will display different content according to different users, different usage environments, and even different times. But if this theme is only used on your blog, then many things will be fixed, such as the blog title. You no longer need the theme to dynamically display these static content, and dynamic code often consumes more time than static content.
Now that we know what dynamic code is, let me introduce how to make your theme code static. It should be noted that the static theme can only be used for your blog. If the domain name and other information are changed, the code will need to be modified again; before starting, you'd better prepare a text that can modify and search multiple files at the same time. An editor, such as UltraEdit, will be more convenient, because the same piece of code will appear in multiple files of the theme. It doesn't matter if you don't have such an editor, but it is best not to use the Notepad that comes with Windows to change the code; in addition, If you modify the code and there is Chinese in it, please save it in UTF-8, otherwise the Chinese will be garbled.
Finally, let me introduce the layout rules of this article. There will be some bold codes under each green main title below. These are dynamic PHP codes that need to be replaced. You can open all the codes in the theme folder. .php file, find these codes and replace them according to the instructions, such as provided in the first item, because the number of spaces and parameters used in different theme codes are different. It’s too similar, so you may not be able to find it by directly searching for the above code. You can just search for language_attributes
. If you have any questions, you can leave me a message. Too much nonsense, sorry! Let’s start with the main topic:
1. Web page language attribute declaration
This function is used to declare The language used by the web page generally appears at the beginning of the header.php
file. If your theme is for a Chinese site and the text direction is read from left to right, you can use the following static content instead of adding The thick piece of code: dir="ltr" lang="zh-CN"
The modified code is similar:
2. bloginfo() blog information function
This function has many parameters (the content in brackets), pass Different parameters can be used to output different blog information. For the specific content of each parameter output, you can take a look at the document: template tag-bloginfo. Let’s pick up a few common ones:
is used to output the "site title" of the blog. As for the site title, you can Find it in the WordPress backend - Settings - General, replace all this code with your "site title"; ##The "subtitle" used to output the blog can be found in the WordPress backend - Settings - General. Replace all this code with your "subtitle";
is used to output the "site address (URL)" of the blog, which can be found in the WordPress backend - Settings - General. Replace all this code with your "site address (URL)" URL)";
Used to output the "style.css file URL" of the blog, if you don't know What is this URL? You can open your blog homepage, and then use the browser's "View Source Code" function to view the source code of the web page. Search for style.css. You should be able to find http://example/wp-content/themes/ default/style.css, just replace this code with this URL;
Used to output the "style "The directory where the .css file is located", that is, remove /style.css from the style.css URL above, such as http://example/wp-content/themes/default, remember there is no / after it;
Used to output the URL of your feed, the general form is: http://example/feed/, if you use Feedsky The class hosts the feed, which can be replaced by the URL provided by Feedsky; The form is as follows: http://example/home/wp/xmlrpc.php, check the source code and search for rel="pingback", you can find this URL; '); ?>
This function is used to declare the encoding of the web page. It usually appears at the beginning of this fileheader.php. This encoding can be found in the WordPress background - Settings - Reading, the last option "page and feed encoding" are set there, usually UTF-8. You can replace this code with: UTF-8
is used to output the version number of WordPress. However, due to security reasons, it is not recommended to use this function. You can replace this code with a non-existent version number, which can also be confusing to a certain extent. effect.
3. get_option() Blog information function
This function can output a lot of blog information like bloginfo(), but it will not print it out directly, but Passed as variable value. This function also has as many parameters as a cow, and I can’t explain them all here. For all the specific parameters, please refer to the document (English): Option Reference
. In addition, the get_settings() function is the same as get_option(). Exactly the same function, get_settings generally appears in some older themes. You can search for get_option in the .php file in the theme directory. You should be able to find many. Here are a few common ones:get_option('home')
This Used to obtain the URL of the blog homepage. It should be noted that all parameter forms of this function cannot be directly replaced by URLs like bloginfo() above, because it does not directly output the value, but must be replaced by quotation marks. For example: you can replaceecho get_option('home'); with echo 'https://www.ludou.org/';
, if it is php echo get_option('home'); ?>, you can directly replace this code with https://www.ludou.org/, these are some simple PHP Programming method, I believe you can also draw inferences about what is said below.
get_option('blogname') Used to get the blog name.
get_option('blog_charset')
4. get_bloginfo() blog information function
If I hadn’t written this article, I wouldn’t have known that WordPress has so many functions that can be used to obtain blog information , and they all have similar functions. To be honest, I can’t figure it out! The replacement method of this function is the same as get_option(). I will not go into details here. For detailed parameter description, please see: get_bloginfo()
5. Chinese theme code
5. Author function
If you are the only one writing your blog, then replace the functions that output author information with your own information. .Used to output the URL of the author archive page, you can replace this function with the following code:
<a href="作者存档页的网址" title="由 XX 发表">作者昵称</a>
用于显示作者的昵称,你可以直接用作者的昵称替换这段代码。
get_the_author();用于获取作者的昵称,你可以用以下内容替换这段代码:'作者昵称';
用于输出作者的网址URL,跟the_author_posts_link函数功能是不一样的。你可以用以下代码代替这段代码:
<a href="作者网站的网址" title="查看 XX 的站点">作者昵称</a>
六、侧边栏静态化
如果你的侧边栏不需要后台的提供的小工具,或者你喜欢直接用代码来实现侧边栏的某些效果,那么你可以删除sidebar.php中的动态调用小工具的代码,前提是你懂HTML、PHP编程。
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('north_sidebar') ) : ?>***<?php endif; ?>
你可以在***所在的位置添加你自己的侧边栏的代码,添加成功后你可以将
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('north_sidebar') ) : ?>
和
<?php endif; ?>
删除,这样WordPress就不会去检测你的小工具了,当然你也不能在后台添加小工具了。
七、友情链接静态化
大多数博客的友情链接都是通过后台的小工具或wp_list_bookmarks()函数来输出,这样做的好处是在后台 - 链接那里添加链接前台就会立刻显示,不用你手动地去修改代码等。如果你追求速度,你还可以将友情链接的代码静态化,上面已经说了sidebar.php去除小工具的方法,已经不能用小工具来显示友情链接了。在删除小工具功能之前,先打开你的博客首页查看源代码,找出友情链接部分的代码,如:
<div class="widget widget_links"> <h3 id="友情链接">友情链接</h3> <ul> <li><a href="http://example/" title="example">example</a></li> <li><a href="http://example2/" title="example2">example2</a></li> </ul> </div>
你可以将这部分代码添加到第六点将到的***部分就可以了。注意:此操作需要你了解HTML,而且每次要修改友情链接的时候需要你手动在sidebar.php中编辑HTML代码。
推荐学习:《WordPress教程》
The above is the detailed content of How to make WordPress theme code static? Tutorial sharing. For more information, please follow other related articles on the PHP Chinese website!

Yes, WordPress is very suitable for e-commerce. 1) With the WooCommerce plugin, WordPress can quickly become a fully functional online store. 2) Pay attention to performance optimization and security, and regular updates and use of caches and security plug-ins are the key. 3) WordPress provides a wealth of customization options to improve user experience and significantly optimize SEO.

Do you want to connect your website to Yandex Webmaster Tools? Webmaster tools such as Google Search Console, Bing and Yandex can help you optimize your website, monitor traffic, manage robots.txt, check for website errors, and more. In this article, we will share how to add your WordPress website to the Yandex Webmaster Tool to monitor your search engine traffic. What is Yandex? Yandex is a popular search engine based in Russia, similar to Google and Bing. You can excel in Yandex

Do you need to fix HTTP image upload errors in WordPress? This error can be particularly frustrating when you create content in WordPress. This usually happens when you upload images or other files to your CMS using the built-in WordPress media library. In this article, we will show you how to easily fix HTTP image upload errors in WordPress. What is the reason for HTTP errors during WordPress media uploading? When you try to upload files to Wo using WordPress media uploader

Recently, one of our readers reported that the Add Media button on their WordPress site suddenly stopped working. This classic editor problem does not show any errors or warnings, which makes the user unaware why their "Add Media" button does not work. In this article, we will show you how to easily fix the Add Media button in WordPress that doesn't work. What causes WordPress "Add Media" button to stop working? If you are still using the old classic WordPress editor, the Add Media button allows you to insert images, videos, and more into your blog post.

Do you want to know how to use cookies on your WordPress website? Cookies are useful tools for storing temporary information in users’ browsers. You can use this information to enhance the user experience through personalization and behavioral targeting. In this ultimate guide, we will show you how to set, get, and delete WordPresscookies like a professional. Note: This is an advanced tutorial. It requires you to be proficient in HTML, CSS, WordPress websites and PHP. What are cookies? Cookies are created and stored when users visit websites.

Do you see the "429 too many requests" error on your WordPress website? This error message means that the user is sending too many HTTP requests to the server of your website. This error can be very frustrating because it is difficult to find out what causes the error. In this article, we will show you how to easily fix the "WordPress429TooManyRequests" error. What causes too many requests for WordPress429? The most common cause of the "429TooManyRequests" error is that the user, bot, or script attempts to go to the website

WordPresscanhandlelargewebsiteswithcarefulplanningandoptimization.1)Usecachingtoreduceserverload.2)Optimizeyourdatabaseregularly.3)ImplementaCDNtodistributecontent.4)Vetpluginsandthemestoavoidconflicts.5)ConsidermanagedWordPresshostingforenhancedperf

WordPress is very customized, providing a wide range of flexibility and customizability. 1) Through the theme and plug-in ecosystem, 2) use RESTAPI for front-end development, 3) In-depth code level modifications, users can achieve a highly personalized experience. However, customization requires mastering technologies such as PHP, JavaScript, CSS, etc., and pay attention to performance optimization and plug-in selection to avoid potential problems.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools
