# Wordpress

# Wordpress學習筆記

##### 安裝wprdpress

```
wget https://tw.wordpress.org/latest-zh_TW.zip
unzip
```

```
mysql -u root -p
create database wordpress;
create user 'wpadmin'@'localhost' identified by 'P@ssw0rd';
grant all on wordpress.* to 'wpadmin'@'localhost';
flush privileges;
```

##### php建議設定

```
memory_limit = 512M
max_execution_time = 900
max_input_time = 900
post_max_size = 256M
upload_max_filesize = 720M
```

##### 路徑修改

```
location / {
    try_files $uri $uri/ /index.php?$args;
}
```

##### 商品設定強制下載

```
# Protect WooCommerce upload folder from being accessed directly.
# You may want to change this config if you are using "Redirect Only" method for downloadable products.
# Place this config towards the end of "server" block in nGinx configuration.
location ~* /wp-content/uploads/woocommerce_uploads/ {
    if ( $upstream_http_x_accel_redirect = "" ) {
        return 403;
    }
    internal;
}
```

**記得安裝 <span style="color: rgb(224, 62, 45);">php-curl php-xml php-gd php-imagick php-bcmatch php-zip php-intl php-redis</span>(有安裝Redis Object Cache)**

##### 基本外掛

elementor(佈景,可以加Blocky或astra)facebookchat(有粉絲頁的話),health check(網站檢查),popup maker（彈跳視窗）,post smtp（寄信）,wordfence security（安全）,wpforms（表單）,wps hide login（登入路徑）,wps limit login（登入次數）,yoast seo（seo 可試試rank math seo）redirection(重新導向檢查與設定)  
newsletter(電子報),Sassy Social Share(社群分享外掛）,wp post view（文章檢視計算）、Duplicate（文章或頁面複製）、Post Views Counter（文章檢視計算）One User Avatar(使用者照片更換)  
線上預約都堪用（bookly）Ultimate Member（會員權限外掛）Shortcoder（短碼外掛） Comment Reply Email Notification（回覆留言寄信通知）Redis Object Cache/Memcached Object Cache

##### 好用

image watermark（照片浮水印）、YARPP – Yet Another Related Posts Plugin （相關文章分享）、Super Socializer (社群登入/評論、分享、按贊)Ad Inserter(廣告)、WP External Links（連結方式設定）

##### wordpress未測試候補：

電子報：sendpress,jackmail,mailster,sumo,sendblue,envato elements(素材庫）  
password strength settings(密碼強度)、erden custom login and dashboard(登入圖示)lucked table of content(目錄)disable comment(停止垃圾留言)GTranslate、TransPress(線上翻譯)、w3 total cache、Media Library Assistant （多媒體資源分類）、Tablepress（表格軟體）、Wordpress popular posts（熱門文章推薦）、Smush – Lazy Load Images, Optimize &amp; Compress Images （照片縮圖）、Polylang（多國語言）、Loco Translate （翻譯外掛）、Content Views – Post Grid &amp; Filter for WordPress （輪轉）

##### 購物網站：

woocommerce(主程式)、ti woocommerce wishlist（願望清單）、RY WC City Select(地址縣市區變清單)、Print Invoice &amp; Delviery Notes for Woocommerce(收據)  
pickplugins product slider(商品輪撥) order delivery date(到貨時間選擇) enhanced ecommerce google anaylist（ga加強）food online for woocommerce(線上訂單gloria food 需要帳號)WooCommerce Google Analytics Integration(進階綁ga)YITH WooCommerce Product Add-Ons（加購選擇）WPC Product Bundles for WooCommerce（組合商品）WPC Frequently Bought Together for WooCommerce（商品加購）、YayMail（更改通知表單） 、CartFlows（一頁式商品行銷網頁）Facebook for WooCommerce（直接將商品同步至粉絲頁）、FiboSearch - AJAX Search for WooCommerce（可以直接搜尋下單） StoreCustomizer（針對woocommerce頁面做更多調整）RY WooCommerce Tools（可以綁定綠界或藍新金流物流）WC Cancel Order（訂單取消申請）YITH WooCommerce Badge Management（商品標籤）、yith woocommerce badge management(商品tag)

##### woocommerce未測試：

wpeverest(woo客戶註冊頁面)、yith woocommerce compare(商品細項比較)Variation Swatches for WooCommerce（商品系項顏色、大小等選項）、wpc product bandles(商品批量編輯)advanced woo search(進階搜尋)Advanced Dynamic Pricing for WooCommerce（動態價錢調整)、Checkout Field Editor（自訂結帳表單）、

WooCommerce 主要頁面類型，短代碼種類（可參考 WooCommerce Shortcodes）  
 \[woocommerce\_cart\]：顯示購物車頁面  
 \[woocommerce\_checkout\]：顯示結帳頁面  
 \[woocommerce\_my\_account\]：顯示用戶帳戶頁面  
 \[woocommerce\_order\_tracking\]：顯示訂單追蹤表單

 {site\_title}：網站標題  
 {order\_number}：訂單編號  
 {order\_date}：訂單日期

##### 限制顯示字數

```
    function title_count_js(){
?>
<script>
jQuery(document).ready(function(){
    //在標題欄位下顯示提示及目前字數。
    jQuery("#titlewrap").after("<div><small>標題字數: </small><input type=\"text\" value=\"0\" maxlength=\"3\" size=\"3\" id=\"title_counter\" readonly=\"\" style=\"background:#fff;\"> <small>最多字數為30個字</small></div>");
    jQuery("#title_counter").val(jQuery("#title").val().length);

    //計算目前字數
    jQuery("#title").keyup( function() {
        jQuery("#title_counter").val(jQuery("#title").val().length);
    });

    //限制字串
    jQuery("#titlewrap #title").keyup( function() {
        var $this = jQuery(this);
        if($this.val().length > 10)//改成想要限制的數字
        $this.val($this.val().substr(0, 10));//這裡也要
    });
});
</script>
<?php
}
add_action( 'admin_head-post.php', 'title_count_js');
add_action( 'admin_head-post-new.php', 'title_count_js');

img.radius {
    width: 500px;#圖寬度
    border-radius: 10px;＃圖圓角
    box-shadow: 0 0 10px rgba(0,0,0,1.00);＃圖陰影
}
```

##### astra ＆ woocommerce 改掉產品頁的out of sold字幕

```
add_filter( 'astra_woo_shop_out_of_stock_string', 'out_of_stock_callback' );
function out_of_stock_callback( $title ) {
return 'SOLD';
}
```

##### 如何顯示留言者的原本ip

```
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$list = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['REMOTE_ADDR'] = $list[0];
}
```