Methods for setting default content in the WordPress article editor _php instances

Source: Internet
Author: User
Many times we need to set the default content for the WordPress article editor, such as the usual beginning or article attention to put in, this article teaches you to the WordPress editor to 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 contents to set ';} Add_filter (' default_content ', ' bing_default_content ');

You can also set the default caption:


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

Add the top two pieces of code and open the Publish article interface by default this is the case:

But what if the site has a lot of custom article types, and each article type wants to set the default content separately?

In fact, you just need a simple judgment, and then return it separately:

/**  *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 of the page ';    break;    Case ' pic ':      $content = ' Picture (custom article type) ' default content ';    break;  }  return $content;} Add_filter (' default_content ', ' bing_default_content ', 10, 2);

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

  • 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.