How to set default content in WordPress post editor, wordpress editor_PHP tutorial

WBOY
Release: 2016-07-12 09:02:03
Original
1011 people have browsed it

How to set default content in WordPress article editor, wordpress editor

Many times we need to set default content for WordPress article editor, such as starting with commonly used Or put in the article notes, and this article will teach you how to set the default content for the WordPress editor.

/**
  *WordPress 给文章编辑器设置默认内容
  *http://www.endskin.com/default-content-title/
*/
function Bing_default_content(){
  return '要设置的默认内容';
}
add_filter( 'default_content', 'Bing_default_content' );
Copy after login

You can also set a default title:


/**
  *WordPress 给文章编辑器设置默认标题
  *http://www.endskin.com/default-content-title/
*/
function Bing_default_title(){
  return '要设置的默认标题';
}
add_filter( 'default_title', 'Bing_default_title' );
Copy after login

After adding the above two pieces of code, the default article publishing interface will look like this:

20151229145858101.png (860×583)

But what if the website has many custom article types and you want to set default content for each article type separately?

In fact, you only need to make a simple judgment and then return separately:

/**
  *WordPress 自定义文章类型分别给编辑器设置默认内容
  *http://www.endskin.com/post-default-content-title/
*/
function Bing_default_content( $content, $post ){
  switch( $post->post_type ){
    case 'post':
      $content = '文章的默认内容';
    break;
    case 'page':
      $content = '页面的默认内容';
    break;
    case 'pic':
      $content = '图片(自定义的文章类型)的默认内容';
    break;
  }
  return $content;
}
add_filter( 'default_content', 'Bing_default_content', 10, 2 );
Copy after login

The default title is similar, just replace the default_content hook with default_title.

Articles you may be interested in:

  • Tips for customizing the color scheme of the backend management interface in WordPress
  • Analysis of related functions for sending http requests in WordPress
  • Explanation of PHP functions used to create and obtain sidebars in WordPress
  • Detailed explanation of how to use functions to add and perform actions in WordPress

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1086652.htmlTechArticleHow to set the default content in the WordPress article editor. In the wordpress editor, many times we need to add articles to WordPress The editor sets default content, such as starting with commonly used...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template