• Home
  • About
    • My Profile
    • Service
    • Portfolio
  • Contact
  • Blogs
Shopping cart close
JODBUSH
  • Home
  • About
    • My Profile
    • Service
    • Portfolio
  • Contact
  • Blogs
close
30 ต.ค.
Blogs

Redirect เปลี่ยนหน้า Login URL WordPress

  • 30/10/2018
  • Posted by weerapol
  • Login, Redirect
  • Leave a comment

สวัสดีครับวันนี้ผมจะมาสอนการทำ Redirect  Login ของ wordpress เป็น URL ที่เรากำหนด เมื่อต้องการเข้าสู่ระบบหรือ สมัครสมาชิก โดยปกติค่า Default ของ wordpress จะเข้ามาที่ https://www.ชื่อเว็บไซต์.com/wp-login.php  แต่เมื่อเราต้องการจะกำหนดหน้าอื่นล่ะ เราจะทำยังไง เราต้องการเป็นหน้าที่เรา Design เป็นหน้าเข้าสู่ระบบ และสมัครสมาชิก ขอเว็บไซต์เรา เราจะต้องทำการ Redirect Login อย่างไร

วิธีการ

การใช้งานก็ง่ายมากครับ ที่ผมจะมาบอกโดยไม่ได้ใช้ Plugin แต่ผมจะใช้การเพิมคำสั่งโค๊ดใน Function Theme ขั้นตอนแรกให้ดำเนินการ Copy โค๊ดชุดนี้ ไป ใส่ใน function.php ใน Theme Folder ของ WordPress  โดนไป Paste ต่อท้ายคำสั่งของ Theme Function ที่มีอยู่แล้ว เพื่อป้องกันการเกิดปัญหา ถ้าไปวางผิดตำแหน่ง  ขั้นตอนที่สอง  บรรทัด wp_redirect ให้ทำการใส่ URL หน้า  Login ที่เราสร้างไว้ เพื่อ เมื่อมีการเรียกเข้า wp-login.php  wp-admin หรือ หน้าอื่นๆ ที่ต้องการที่จะต้องเข้าสู่ระบบ ระบบก็จะทำการ Redirect URL ไป ยังหน้า ที่เรากำหนด URL ไว้


function possibly_redirect(){
global $pagenow;
if( 'wp-login.php' == $pagenow ) {
  if( isset( $_POST['wp-submit'] ) || 
    // in case of LOGIN
    ( isset($_GET['action']) && $_GET['action']=='logout') || 
    // in case of LOGOUT
    ( isset($_GET['checkemail']) && $_GET['checkemail']=='confirm') || 
    // in case of LOST PASSWORD
    ( isset($_GET['checkemail']) && $_GET['checkemail']=='registered') ) return; 
    // in case of REGISTER
  else wp_redirect('https://www.ชื่อเว็บไซต์.com/login'); 
   // or wp_redirect(home_url('/login'));
exit();
}
}
add_action('init','possibly_redirect');

หลังจากที่ทำการใส่ โค๊ด ถูกต้องให้ทำการลองทดสอบเรียก URL https://www.ชื่อเว็บไซต์.com/wp-login.php ว่าเมื่อมีการเข้า wp-login.php แล้วเว็บไซต์ Redirect URL ไปที่เราใส่ไว้หรือป่าว ถ้ายังไม่เปลี่ยนแต่คิดว่าใส่ URL ถูกต้องแน่นอน ให้ทำการ Clear Browser Cache ดูครับผม  สำหรับใครที่เป็นมือใหม่ยังไม่เข้าใจว่าใส่ตรงไหน ลองคอมเม้นไว้ได้เลยครับ หรือทักมาถามใน Facebook FanPage ก็ได้ครับผม

 

  • FacebookFacebook
  • XTwitter
  • LINELine
  • Facebook
  • X
  • Email
  • Pinterest
  • LinkedIn
Close
Recent Posts
  • เปลี่ยน WordPress 5.0 ใช้งาน Classic Editor

  • WordPress เพิ่มความปลอดภัยกับ Hosting

  • WordPress เพิ่มความปลอดภัยในส่วนของ Database

  • WordPress เพิ่มความปลอดภัยในหน้า Admin Dashboard

  • WordPress เพิ่มป้องกันการโจมตีจาก brute force attacks

  • Traffic มีความสำคัญต่อ SEO เป็นอย่างมาก

  • การตั้งค่าเปิดการใช้งาน HSTS บน Cloudflare

  • การเปิดการใช้งาน HSTS ใน WordPress

  • Facebook แอบเพิ่ม Parameter ในการเชื่อมโยงลิงค์

  • ตรวจสอบ สถานะ Cloudflare CDN

Copyright © 2014-2023 Jodbush.com All Right Reserve  | Designed By Weerapol Chindamat

JODBUSH
JODBUSH
creative web design
  • หน้าแรก
  • รู้จักเรา
    • เกี่ยวกับเรา
    • สนใจทำเว็บไซต์
    • ตัวอย่างผลงาน
  • ช่องทางการติดต่อ
  • บทความ
  • My Profile
  • Service
  • Contact Form
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}