函数钩子 功能说明 备注
add_management_page() 在Tools下面创建
add_options_page() 在Settings下面创建
add_theme_page() 在Appearance下面创建
add_users_page() 在Users下面创建
add_dashboard_page() 在Dashboard下面创建
add_posts_page() 在Posts下面创建
add_media_page() 在Media下面创建
add_links_page() 在Links下面创建
add_pages_page() 在Page下面创建
add_comments_page() 在Comments下面创建
add_menu_page() 创建一个新的主菜单项,与Tools,Settings等平级
add_menu_page ( string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '', string $icon_url = '', int $position = null )
(string) (Required) The text to be displayed in the title tags of the page when the menu is selected.
(string) (Required) The text to be used for the menu.
(string) (Required) The capability required for this menu to be displayed to the user.
(string) (Required) The slug name to refer to this menu by (should be unique for this menu).
(callable) (Optional) The function to be called to output the content for this page.
Default value: ''
(string) (Optional) The URL to the icon to be used for this menu. <em> Pass a base64-encoded SVG using a data URI, which will be colored to match the color scheme. This should begin with 'data:image/svg+xml;base64,'. </em> Pass the name of a Dashicons helper class to use a font icon, e.g. 'dashicons-chart-pie'. * Pass 'none' to leave div.wp-menu-image empty so an icon can be added via CSS.
Default value: ''
(int) (Optional) The position in the menu order this one should appear.
Default value: null



wordpress 开发插件或者主题的时候,调试时必不可少的。现在记录一下,一直以来的迷惑

For simple WordPress theme development, what is the first thing most PHP developers do to troubleshoot problems?

print_r( $post );

One the statements are in place, the programmer refreshes the page and looks at the source to view a nicely indented array or object. Next they comment out the print_r and die statements, change some lines, and try the code again. If it fails, they are back to square one and in go theprint_r,echo and die statements so the brutal cycle can begin again.

We know these methods partially work (who hasn’t done the above during a PHP project!), but we also know they are less than optimal. Is there a better way?

WordPress Debug Mode

WordPress offers quite a few ways to enable and customize a debug mode while developing. To enable debug mode, you want to define WP_DEBUG as true in your wp-config.php. Here is the complete code block I suggest you use. We will look at the individual parts shortly. Place this in your wp-config.php file after the lines that define the database variables. Be sure to change development_user to be your development database user name:

if( 'development_user' === DB_USER ){
  define('WP_DEBUG',         true);  // Turn debugging ON
  define('WP_DEBUG_DISPLAY', false); // Turn forced display OFF
  define('WP_DEBUG_LOG',     true);  // Turn logging to wp-content/debug.log ON


The first line in our code block turns off the display of errors, regardless of php.ini or .htaccess settings to the contrary. This is important because though WordPress can force the display of errors to be on, it won’t force them to be off if display_errors is already turned on.


There are probably fifty ways of doing this part, so use a method that works for you. In my environments, my local development database rarely if ever has the same user name as the production database. Simply checking what I expect the local user name to be against what is defined in DB_USER is a simple way of knowing if the files are on the development or production servers.


This is the most important constant as it determines if WordPress will use any of the other debugging constants. Thankfully it is quite simple. If set to true, debug mode is turned on. Ifundefined or set to false, debug mode is kept off.


This constant confused me at first, but it is actually quite simple. If set to true, it will override the current display_errors configuration setting and turn it on. However, if set to false it will not turn off display_errors. This setting is simply an override. This is the reason we turndisplay_errors off before setting any of these constants.

Set this constant to true if you want to see errors displayed in your browser when they occur. Keep in mind this will sometimes complicate errors because once at least one error has been written to the page, all redirect requests will fail. This is because the header information can no longer be modified once content is sent, and a displayed error counts as content.


This constant is the whole reason I found the WordPress debug methods so helpful. Set this constant to true and WordPress will set up PHP to write to an error log in wp-content/debug.log. Sadly you can’t specify a different file location that is not in the content folder, but at least you know where it is!

Note: because this is written to a public directly, be extremely careful not to upload the log by mistake. Additionally, if you run WP_DEBUG on a production server, do so only for immediate troubleshooting then turn it off and remove wp-content/debug.log.

Leveraging WP_DEBUG

In addition to PHP errors being sent to debug.log we can also send our own output using theerror_log PHP function. The only problem with this, is even in production mode your errors will still most likely be written to a PHP log; it just won’t be debug.log. Because of this, its a good idea to provide a wrapper function to handle the logging for your theme or plugin.

Place the following code in your functions.php in your theme, or in the plugin file for your WordPress plugin:

  function _log( $message ) {
    if( WP_DEBUG === true ){
      if( is_array( $message ) || is_object( $message ) ){
        error_log( print_r( $message, true ) );
      } else {
        error_log( $message );


Feel free to expand on this function if it doesn’t exactly meet your needs, but the concept is simple: Centralize all your log calls to use your custom function. Then, in that _log function, only output the message if WP_DEBUG is set to true. There is no reason to test if WP_DEBUG has been defined because as soon as wp-settings.php is processed, WP_DEBUG will bedefined, even if it wasn’t already defined in wp-config.php.

This particular _log snippet will call a print_r on arrays and objects passed to the function for simple debugging.

Trying it Out

If you have followed these steps, you can run a quick test by adding these lines into yourheader.php file in your theme folder:

_log('Testing the error message logging');
_log(array('it' => 'works'));

After refreshing your page once, you should see a newly created debug.php file with a few lines of output. Use any log viewing utility that supports tailing the file for maximum productivity. On Mac, Unix and Linux systems, you can use this command from the main directory of your site:

tail -f wp-content/debug.log


More Solutions

If you are looking for a more interactive console for debugging, be sure to look at our review on the WordPress Console.


PHP 7发布了。据说性能什么的上升了不止一个档次。对于我们这些小白鼠早就迫不及待的升级。昨晚编译升级,可是频繁出现500的错误。经过排查,现在归纳正确的升级方式:

  1. 这是最重要的。一定要先禁用你的所有插件。因为如果插件和PHP7有不兼容的地方,将会导致直接无法使用。返回500的错误。我在升级的时候就遇到这样的错误:升级,但是由于W3-TOTAL-CACHE中启用的Memcached的功能,而且我在安装PHP7的时候,发现Memcache扩展根本安装不上的。
  2. 编译安装。建议保留原来的PHP版本,例如更好目录/usr/local/php7 这样的
  3. 编译参数保持原来一致。
  4. 重新启用插件,注意,最好一个个启用或者一批批启用。不过如果启用有问题的话,会自动禁用的。



Yoast WordPress SEO Plugin 设置

Yoast SEO Plugin Settings


The Yoast WordPress SEO Plugin by Joost De Valk is the most robust SEO plugin out there, but it must be setup and used properly if you want the best results for your SEO. This starts with configuring the different SEO tabs on the left of your dashboard once Yoast is installed.

Every website is different, so the best Yoast SEO plugin settings may be slightly different for each website. Just make sure you’ve updated Yoast before configuring the settings. I wrote separate tutorials on choosing focus keywords and optimizing content for green lightswhich are the next steps after configuring the settings – I would read those as well. I know there’s a lot to this tutorial so leave a comment if you have any questions. I’m here to help.


Upload My Yoast Settings To Your WordPress Site

If you want to use the same Yoast settings I use, download the zip file below. Upload it under SEO –> Tools –> Import And Export –> Import.


Things You Will Still Need To Do:


Table of Contents

1. Installation
2. General
3. Titles & Metas
4. Social
5. XML Sitemaps
6. Advanced
7. Tools
8. Webmaster Tools
9. Extensions

10. Choosing Focus Keywords
11. Optimizing Content For Green Lights
12. Social Media Optimization


1. Installation

Go to plugins –> add new –> search “WordPress SEO by Yoast” –> install/activate. You will now see the different Yoast tabs on the left side of your dashboard.

WordPress SEO by Yoast Installtion


2. General

Yoast General Settings Tab

Yoast Company Info

Logo should be at least 200×200 pixels – same with “image URL” in the Facebook social tab.

Yoast Webmaster Tools

Webmaster Tools

  • Sign up for Google Search Console (formerly Google Webmaster Tools)
  • During the verification process, select the “HTML tag” option
  • Copy the code
  • Paste code under SEO –> General –> Webmaster Tools –> Google Search Console
  • Delete everything outside of the quotations (including the quotations)
  • Save changes in Yoast
  • Click “Verify” in Google Search Console
  • Repeat for Bing and Yandex (Russia’s largest search engine), both of which have a similar verification process where you delete everything outside the quotations

Yoast Security Tab

Noindex – means you’re choosing not to index (publish) something in search engines


3. Titles & Metas

Yoast General Settings

Force Rewrite Titles
A common issue with Yoast is having duplicate sitenames in the SEO title. To see if this is happening to you, open your site and hover over the browser tab to check for duplicates:

Duplicate Title Tags

Selecting the Force Rewrite Titles under “Titles & Metas” should fix the duplicate sitename, but it’s not the preferred solution according to Yoast since it can slow down your site. The preferred solution is to go to Appearance –> Editor –> Header.php, then delete everything between <title> and </title. You’ll want to replace it with this code:

<title><?php wp_title(''); ?></title>

Doing this affects the title tag structure for all pages so it’s a good idea to double check how they appear after you change the settings (again, by hovering over the browser tab).

Yoast Homepage Settings

Yoast Post Types

If when editing your content you don’t write a custom SEO title and meta description (though you should since these are the forefront of your SEO which appear in search results), these will be your default templates. Here are other templates you can use:

Yoast Basic Variables


常用变量补充(点击旁边的?help 按钮就可以出来了):

Basic Variables

%%date%% Replaced with the date of the post/page
%%title%% Replaced with the title of the post/page
%%parent_title%% Replaced with the title of the parent page of the current page
%%sitename%% The site’s name
%%sitedesc%% The site’s tagline / description
%%excerpt%% Replaced with the post/page excerpt (or auto-generated if it does not exist)
%%excerpt_only%% Replaced with the post/page excerpt (without auto-generation)
%%tag%% Replaced with the current tag/tags
%%category%% Replaced with the post categories (comma separated)
%%category_description%% Replaced with the category description
%%tag_description%% Replaced with the tag description
%%term_description%% Replaced with the term description
%%term_title%% Replaced with the term name
%%searchphrase%% Replaced with the current search phrase
%%sep%% The separator defined in your theme’s wp_title() tag.

The following sample of variables require a better understanding of SEO. If you’re unsure about how to correctly use this, don’t. Or you can book a training at Yoast.

Advanced Variables

%%pt_single%% Replaced with the post type single label
%%pt_plural%% Replaced with the post type plural label
%%modified%% Replaced with the post/page modified time
%%id%% Replaced with the post/page ID
%%name%% Replaced with the post/page author’s ‘nicename’
%%userid%% Replaced with the post/page author’s userid
%%currenttime%% Replaced with the current time
%%currentdate%% Replaced with the current date
%%currentday%% Replaced with the current day
%%currentmonth%% Replaced with the current month
%%currentyear%% Replaced with the current year
%%page%% Replaced with the current page number (i.e. page 2 of 4)
%%pagetotal%% Replaced with the current page total
%%pagenumber%% Replaced with the current page number
%%caption%% Attachment caption
%%focuskw%% Replaced with the posts focus keyword
%%term404%% Replaced with the slug which caused the 404
%%cf_<custom-field-name>%% Replaced with a posts custom field value
%%ct_<custom-tax-name>%% Replaced with a posts custom taxonomies, comma separated.
%%ct_desc_<custom-tax-name>%% Replaced with a custom taxonomies description




Write Unique Meta Descriptions
If you’re using my default templates in the “Post Types” settings, your page title will now be used as the your SEO title, only your sitename will appear at the end. Same with your posts. These are good templates, and this means you can probably get away with not writing custom SEO titles anymore (unless you want them different from your page/post title).

But you should be writing unique meta descriptions for every page/post (the longer descriptions that appear in search results), otherwise an excerpt will be used which is a short description taken automatically from your content (not preferred). So even though your meta description has an OK template, I would always write unique meta descriptions.

Meta Robots – whether something is indexed in search engines (similar to noindex)

Date in Snippet Preview – selecting this will show each article’s publish date in search results (careful, this can make your content look outdated over time)

WordPress SEO Meta Box – selecting this will hide Yoast’s content optimization options (the meta box) when editing a page, post, category, etc

Yoast Taxonomies (2)

I keep my tags noindexed to prevent duplicate content penalties.

Yoast Archives

Yoast Other Tab

Noindex subpages of archives
If you have articles where a “next” button is used to get to /page2 then you probably want the first page to show up in search results (not the second), so this should be checked.


4. Social

Filling out Yoast’s social settings helps Google learn about your social profiles. They also help format your content so it displays properly in search engines AND when it’s shared on main social networks using Facebook Open GraphTwitter Cards, and Google+ meta data.

Yoast Social Settings

Yoast Facebook

Yoast Twitter

Yoast Pinterest

You will need to complete a few additional steps to verify your site with Pinterest.

Google+ Settings


5. XML Sitemaps

General Yoast XML Sitemap Settings

Submitting Your Yoast XML Sitemap To Google Search Console:

  • Go to SEO –> XML Sitemaps
  • Click the XML Sitemap button
  • Copy the last past of the URL, which should be: /sitemap_index.xml
  • Login to Google Search Console
  • On the left, go to Crawl –> Sitemap
  • Paste the last part of the URL (screenshot below)
  • Test and submit
  • Repeat for Bing and Yandex

Yoast Sitemap

Yoast User Sitemap

Yoast Post Types Sitemap Settings

Yoast Taxonomies Sitemap


6. Advanced

Yoast Breadcrumb Settings

Breadcrumbs are the navigation text that appears at the top of your content:


It helps users and search engines learn your content and site structure. I don’t use breadcrumbs to prevent clutter, but I recommend them if you don’t mind the extra text.

To enable breadcrumbs, add this code to Editor –> Index.php. Paste under get_header();

get_header(); ?>
<div id="primary"> 
<?php if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb('<p id="breadcrumbs">','</p>');
} ?>
<div id="content" role="main">

Yoast Permalink Settings

Strip The Category Base From The Category URL
If your permalink structure has the word “category” in it (not preferred), this will remove it. Removing this from your permalink structure will cause your URLs to change though, so setting up a 301 redirect for each URL this affects would be a wise decision.

Redirect Attachment URL’s To Parent Post URLs
When you upload an image, PDF, or any file to WordPress, that file is stored in your media section and also becomes searchable. Selecting this will redirect visitors who find that file URL to the parent post URL (the URL it was uploaded to).

Remove Stop Words From Slugs
Stop words are words like (the, a, and, how) and other words that aren’t descriptive and can cause long, not keyword-rich permalinks. Selecting this will remove stop words from your permalink. It won’t automatically change permalinks already published posts, only when you hit “save” or “publish.” I prefer to control my permalinks, so I leave this unchecked.

Remove The ?replytcom
This removes these types of URLs: http://yoast.com/user-contact-fields-wordpress/#comment-110294 which is good since it prevents duplicate content and improves search engine crawling efficiency. This Moz thread does a good job of explaining it.

Enforce A Trailing Slash On All Category And Tag URLs
If you have .html at the end of your URLs, this option will remove it – which is a good thing.

Redirect Ugly URL’s To Clean Permalinks
If people use an incorrect letter or parameter when they’re linking to you, this option attempts to redirect that link to the correct URL. This is not recommended since it clearly states in the Yoast SEO settings that this option can cause problems.

Yoast RSS Settings

In your feed, here’s what will appear before each post…


And here’s what will appear after each post…



7. Tools

Yoast Tools Tab

Bulk Editor
Your SEO titles and meta descriptions are the forefront of your SEO (they’re the descriptions that appear in search results), so going through these and making sure they’re well-written is good idea. This will improve your clickthrough and potentially your traffic.

Editing meta descriptions can be super helpful since these are summaries of your content and can usually be tweaked to sound better (while including your focus keyword of course):

Bulk Meta Description Editor

File Editor
Allows you to edit robots.txt and .htaccess files.

Import And Export
Use the import button to upload my recommended Yoast settings (zip file) to your website. If you manage multiple sites, you can export your own settings and upload them to those sites.

Yoast Import SEO Plugin


8. Search Console

Yoast recently added a Search Console option to their settings. This allows you to access (some) information from Google Search Console (formerly Google Webmaster Tools) directly into Yoast. Start by clicking “Get Google Authorization Code” to authenticate…

Yoast Google Search Console Authentication

Here you will find different types of errors (page not found, server errors, soft 404s…). You can fix these by setting up 301 redirects which come with Yoast’s premium version, however you can use a free plugin like Quick Page/Post Redirect to do this quite easily.

Yoast Google Search Console

To setup a 301 redirect using Quick Page/Post Redirect, install the plugin then go to Quick Redirects –> Quick Redirects. The old URL should be the one you see in Yoast, the new URL should be whatever URL you want you want it redirected to. See the example…

301 Redirect WordPress


9. Extensions

Yoast Plugins

The Yoast extensions are premium (paid) plugins for specific SEO needs…


10. Choosing Focus Keywords

Google Autocomplete Keywords



11. Optimizing Content For Green Lights

Yoast Page Analysis



12. Social Media Optimization

When editing a page/post, you’ll see a “social” tab in Yoast (see below). By uploading an image for Facebook/Twitter/Google+ with the correct dimensions for each social network (see dimensions below), that page/post will show an image that is formatted correctly to be shared across those networks. Yes, this means you must create a new graphic for each one.

  • Facebook Image: 1200 x 628px
  • Twitter Image: 1024 x 512px
  • Google+ Image: 800 x 1200px

You can also give the post a unique title/description when it’s shared, otherwise the SEO title and meta description will be used, which is OK with me so I always leave those blank.

Yoast Social Media Optimization


Questions? Comments? Drop Me A Line!

I know there’s a lot to configuring the Yoast SEO plugin settings so leave me a comment if you have any questions. When you’re done, check out my other Yoast tutorials on choosing focus keywords and optimizing content for green lights. They are both just as thorough.

Before you say goodbye, if you liked my article, please consider sharing it on your favorite social network. The social share buttons make it easy and I would really appreciate it.

via: http://onlinemediamasters.com/


RT-18作为一款国外经典的用来做企业网站的WordPress主题,也得到DIYzhan.com 网友的大量好评。网友在使用的过程中,向我提出了一些关于RT-18主题的问题。现在针对这些问题做个总结,以使得改善RT-18主题更适合做外贸网站的朋友们。

  • 给RT-18自带的Product功能产品页面添加Tags(产品标签)


  1. 下载文件包,点击下载;里面有2个文件,分别是:\rttheme18\functions.php 和 \rttheme18\product-contents\single-products-content.php ;rt-18-improve3
  2. 登陆你空间的文件管理器,或者使用FTP访问网站根目录;
  3. 使用第一步下载下来的文件包里面的文件替换网站根目录下对应的文件;rt-18-improvert-18-improve2
  4. 完成了。(注意:只针对RT-18主题1.6.1版本测试过,替换文件前,请先备份原来的文件)
  • 给RT-18自带的Product功能产品添加复制产品功能后

如果我们使用woocommerce作为产品列表,那么我们添加商品的时候是可以给通过复制已有的商品来编辑成新的商品。但原来RT-18自带的产品展示功能中添加商品后,我们只能一个个添加商品,并不能在复制已有的商品;这对于有很多有类似商品的外贸网站是不方便的。其实要在原来RT-18自带的产品功能中实现复制功能也很简单,只有安装一个插件就可以了,那就是 duplicate post 这个插件,大家可以在后台搜索安装这个插件。

另外大家对RT-18主题有什么建议,可以进免费互助Q群: 341812967 交流。

  • 加速RT-18主题网站在国内浏览速度的设置


  1. 更换非google字体,在RT-18主题设置的Typography Options里更换;no_google_fonts
  2. 在RT-18主题设置的General Options里,找到Animated Content Blocks,不要勾选;animated_content_block
  3. 使用Revolution Slider创建头部的幻灯片;并在首页的对应的 template里面,把原来的slider换成revolution slider。revolution_slider

以上设置完成之后,再打开你的网站,看看速度是不是快了很多?不过这样就没有了RT-18主题原来有点炫的那种动态效果,如果你需要,就要勾选Animated Content Blocks了。