發佈日期: 發佈留言

Code Snippets 筆記

Visits: 2

添加到 header.php
add_action( ‘wp_head’, function () { ?>
//
<?php } );


添加到footer.php
add_action( ‘wp_footer’, function () { ?>

<?php } );


添加CSS
add_action( ‘wp_head’, function () { ?>
//<style>
// write your CSS code here
//</style><?php } );


add_shortcode( ‘ending’, function () {
//php code
} );


add_action( ‘after_setup_theme’, function() {
//php code
});


加入你的 wp-config.php 檔案
define (‘EMPTY_TRASH_DAYS’, 7);清空回收桶
define (‘EMPTY_TRASH_DAYS’, 0);停用回收桶
define( ‘WP_POST_REVISIONS’, 3 );減少文章版本
define( ‘WP_POST_REVISIONS’, false );停用文章版本功能
define( ‘AUTOSAVE_INTERVAL’, 60 ); // 秒自動儲存你的文章和頁面
define( ‘WP_DEBUG’, true );開啟 PHP 除錯工具
define( ‘SCRIPT_DEBUG’, true ); 開啟 CSS 和 JavaScript 除錯工具
define(‘WP_SITEURL’, ‘http://www.chungg.com’);指定網站網址
define(‘WP_HOME’, ‘http://www.chungg.com/wordpress’);指定 WordPress 網址(安裝目錄)
define( ‘WP_CACHE’, true );啟用 WP 快取
define( ‘WP_ALLOW_MULTISITE’, true );啟用 WordPress 多網站
define( ‘NOBLOGREDIRECT’, ‘http://www.chungg.com’ );重新導向不存在的子網域和子目錄
define( ‘WP_ALLOW_REPAIR’, true );啟用內建資料庫最佳化功能
define( ‘AUTOMATIC_UPDATER_DISABLED’, true );停用所有自動更新
define( ‘WP_AUTO_UPDATE_CORE’, false );停用所有核心更新
define( ‘WP_AUTO_UPDATE_CORE’, true );啟用所有核心更新,包括跨版本更新及主要更新
define( ‘WP_AUTO_UPDATE_CORE’, ‘minor’ );啟用核心更新,但只針對安全性更新(預設)
define( ‘WP_MEMORY_LIMIT’, ’96M’ );為網站設定記憶體限制
define( ‘WP_MAX_MEMORY_LIMIT’, ‘128M’ );為控制台設定記憶體限制
define( ‘FORCE_SSL_ADMIN’, true );強制 SSL 模式登入
define( ‘DISALLOW_FILE_EDIT’, true );停用外掛和佈景主題編輯器
define( ‘DISALLOW_FILE_MODS’, true );停用外掛和佈景主題編輯器,加上外掛和佈景主題更新,所以如果你啟用這項設定,就不用再額外加入 DISALLOW_FILE_EDIT。
define( ‘IMAGE_EDIT_OVERWRITE’, true );清理圖片編輯
define( ‘DISALLOW_UNFILTERED_HTML’, true );禁止編審和系統管理員使用未篩選的 HTML

將 wp-content 目錄移動到其他路徑
define( ‘WP_CONTENT_DIR’, dirname(__FILE__) . ‘/new/wp-content’ );
或define( ‘WP_CONTENT_URL’, ‘https://www.chungg.com/new/wp-content’ );
重新命名你的 wp-content 目錄:define (‘WP_CONTENT_FOLDERNAME’, ‘newfoldername’);並非 100% 可行,因為很多 WordPress 外掛開發者已將 “wp-content” 路徑寫死在外掛的程式碼裡。


加入佈景主題的 functions.php 檔

將作者頁面鏈結重新導向「關於」頁面
add_filter( ‘author_link’, ‘my_author_link’ );
function my_author_link() {
return home_url( ‘about’ );
}

當搜尋結果只有一篇文章時自動連到文章
add_action(‘template_redirect’, ‘redirect_single_post’);
function redirect_single_post() {
if (is_search()) {
global $wp_query;
if ($wp_query->post_count == 1 && $wp_query->max_num_pages == 1) {
wp_redirect( get_permalink( $wp_query->posts[‘0’]->ID ) );
exit;
}
}
}

將頁面從 WordPress 搜尋結果排除
function filter_search($query) {
if ($query->is_search) {
$query->set(‘post_type’, ‘post’);
}
return $query;
}
add_filter(‘pre_get_posts’, ‘filter_search’);

從你的迴響表單移除網址欄位
function remove_comment_fields($fields) {
unset($fields[‘url’]);
return $fields;
}
add_filter(‘comment_form_default_fields’,’remove_comment_fields’);

為迴響內容設定最少字數限制
add_filter( ‘preprocess_comment’, ‘minimal_comment_length’ );
function minimal_comment_length( $commentdata ) {
$minimalCommentLength = 20;
if ( strlen( trim( $commentdata[‘comment_content’] ) ) < $minimalCommentLength ){
wp_die( ‘所有留言必須大於 ‘ . $minimalCommentLength . ‘ 個字元長度。’ );
}
return $commentdata;
}


*網路無遠弗屆!與您簡單分享從這些科技輔具相關資源之所學經驗,錯漏之處在所難免,尚祈各方不吝指正,欲求詳盡,善用網路搜尋!知識技術無價,應用服務有價!

本頁連結(1085442386):Code Snippets 筆記

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

This site uses User Verification plugin to reduce spam. See how your comment data is processed.

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料