How to set default content in the WordPress article editor _php instance

Source: Internet
Author: User

Most of the time we need to set the default content to the WordPress article editor, such as the common beginning or article attention items, this article will teach you to the WordPress editor set the default content.

/**
  *wordpress Set default content to the story editor
  *http://www.endskin.com/default-content-title/
/
function Bing_ Default_content () {return
  ' default content to set ';
}
Add_filter (' default_content ', ' bing_default_content ');

You can also set the default caption:


/**
  *wordpress Set the default title for the story editor
  *http://www.endskin.com/default-content-title//
function Bing_ Default_title () {return
  ' default caption to be set ';
}
Add_filter (' Default_title ', ' bing_default_title ');

After you add the top two pieces of code, open the Publish article interface this is the default:

But what if the site has many custom article types and each article type wants to set the default content separately?

In fact, only need to judge a simple, and then return to each:

/**
  *wordpress Custom article types set default content to the editor
  *http://www.endskin.com/post-default-content-title/
* *
function Bing_default_content ($content, $post) {
  switch ($post->post_type) {case
    ' post ':
      $content = ' The default content of the article ';
    break;
    Case ' page ':
      $content = ' Default content for page ';
    break;
    Case ' pic ':
      $content = ' default content for picture (custom article type) ';
    break;
  return $content;
}
Add_filter (' default_content ', ' bing_default_content ', 10, 2);

The default title is similar, just want to change default_content hook to Default_title can.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.