• Home
  • Blog
  • 如何在您的 WordPress 文章編輯器中添加預設內容

如何在您的 WordPress 文章編輯器中添加預設內容

0 comments

您是否經常在所有的文章中輸入相同的文字?例如,請求讀者訂閱您的內容、轉發文章、在 Facebook 上分享等。您可以使用簡單的標籤來在內容後添加這些文字,或者您可以將這些文字設置為 WordPress 文章編輯器中的預設內容。

步驟

首先,打開您的 WordPress 主題的 functions.php 文件,然後在 PHP 標籤內粘貼以下代碼:

add_filter('default_content', 'my_editor_content');
function my_editor_content($content) {
  $content = "如果您喜歡這篇文章,請考慮在 Twitter 上轉發或在 Facebook 上分享它。";
  return $content;
}

粘貼代碼後就完成了。嘗試創建一篇新文章,您應該會在編輯器中看到新的預設內容。

更新(2013年1月24日)

我們的一位用戶在評論中詢問如何為不同的文章類型添加不同的內容。以下代碼將向您展示如何在每個特定的自訂文章類型中添加不同的預設內容:

add_filter('default_content', 'my_editor_content', 10, 2);
function my_editor_content($content, $post) {
  switch($post->post_type) {
    case 'sources':
      $content = '您的內容';
      break;
    case 'stories':
      $content = '您的內容';
      break;
    case 'pictures':
      $content = '您的內容';
      break;
    default:
      $content = '您的預設內容';
      break;
  }
  return $content;
}

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>