Tag: WordPress

  • Fixing Loopback Request Issue in WordPress in Docker

    If Site Health shows “Your site could not complete a loopback request” (or The REST API encountered an error) when running WordPress in Docker behind a reverse proxy (e.g., Caddy), the culprit is often that extra_hosts entry pointing to a container IP that changes on restart. Which is always as a solution to solve the loopback issue.

    The fix (use a Docker network alias)

    Let Docker’s built-in DNS keep things in sync by giving your proxy container a network alias that matches your site’s domain. Then all other containers resolve the alias to the current IP automatically. Would be a better solution than specifying the internal IP for PHP container:

    services:
      caddy:
        # ...your existing caddy config...
        networks:
          default:
            aliases:
              - example.com

    Now remove any extra_hosts lines you previously added to other services (like php).

    Apply & verify

    # Recreate containers
    docker compose up -d
    
    # From the php container, confirm the alias resolves
    docker compose exec php getent hosts example.com
    
    # (Optional) Hit wp-cron directly
    docker compose exec php curl -I https://example.com/wp-cron.php?doing_wp_cron=1

    Return to Tools → Site Health and re-check: loopback should pass, and scheduled tasks will run normally.

  • Custom WordPress robots.txt Without Plugins

    Inspired by Modify the robots.txt file from wpvip.com

    /**
     * Custom robots.txt
     */
    if ( ! function_exists( 'custom_robotstxt' ) ) :
      function custom_robotstxt() {
        echo "User-agent: MJ12bot" . PHP_EOL;
        echo "Disallow: /" . PHP_EOL;
      }
      add_action( 'do_robotstxt', 'custom_robotstxt' );
    endif;
  • Allow WordPress Embedded Posts with Global X-Frame-Options for Nginx Servers

    The problem: when you enables X-Frame-Options globally. You won’t be able to embed your posts with latest WordPress embed posts method.

    The solution: you can simply exclude it in your Nginx configuration. I’ll use Nginx map for better performance:

    map $request_uri $x_frame_options_headers {
      default                 SAMEORIGIN;
      # Matching WordPress embed page, ie. https://example.com/my-post/embed#?secret=vLi4CQcWkH
      ~/embed                 "";
    }
    
    # Don't allow the browser to render the page inside an frame or iframe
    add_header X-Frame-Options $x_frame_options_headers;
    Embedding Demo
  • Reset WordPress password using MySQL / phpMyAdmin

    UPDATE `wp_users` SET `user_pass`= MD5('yourpassword') WHERE `user_login`='yourusername';
    
  • How to Use cURL to Submit WordPress Comments

    curl --data curl --data "author=Steve Jobs&[email protected]&url=http://www.apple.com&comment=Great Post&comment_post_ID=2801" http://domain.tld/wp-comments-post.php
    
  • Fix svn: warning: ‘wp-content/plugins/akismet’ is not a working copy

    rm %WP_ROOT/wp-content/plugins/akismet/
    cd %WP_ROOT/
    svn up
    
  • Add / Update Assets Images to Remote WordPress Repository Outside Local git-svn Repository

    # Check out remote repo after updating from git repo
    svn co http://plugins.svn.wordpress.org/plugin-name
    
    # Enter plugin folder
    cd plugin-name
    
    # Add new assets
    svn add assets/*
    
    # Commit to remote repo
    svn ci -m 'Add assets image'
    
  • 禁用 global_terms_enabled 以允许 WordPress Mutisite 用户编辑 category slug 与 tag slug

    方法一,编辑数据库 wp_sitemeta 表中的 global_terms_enabled,将值设置为 0

    方法一,插件:

    // disable global terms to make category, link_category, and tag slugs editable
    // you can also set global_terms_enabled value to 0 on wp_sitemeta table
    function disable_global_terms($enablefalse) {
       return 0;
    }
    add_filter( 'global_terms_enabled', 'disable_global_terms' );
    
  • Postfix 发送邮件至本地报错 status=bounced (unknown user: “***”) 的解决办法

    有时候如果你需要发送的邮件与本机 hostname 相同时(例如 WordPress 帐号需要重置密码),但发现无法收到邮件,那么你打开 log 可能会发现这样的问题

    postfix/local[19499]: B2E312E701: to=, relay=local, delay=0.05, delays=0.03/0.01/0/0.01, dsn=5.1.1, status=bounced (unknown user: "usr")

    一个简单的办法是修改 Postfix 的 main.cf 配置文件,将 mydestination 设置为空

    mydestination = 

    之后问题解决:

    postfix/smtp[19838]: 68C072E701: to=, relay=aspmx.l.google.com[173.194.79.26]:25, delay=1.4, delays=0.03/0.01/0.29/1.1, dsn=2.0.0, status=sent (250 2.0.0 OK 1335520194 t9si6294951pbj.252)
  • 让 SyntaxHighlighter Evolved 变好看的 CSS

    凡是用 WordPress 贴代码的基本都会用 SyntaxHighlighter Evolved 插件,因为 wordpress.com 就在用,但凡是用了 SyntaxHighlighter Evolved 的样子都奇丑无比,让人恶心,下面提供一下本站使用的 CSS 样式,让你的代码可以瞬间从无数没有审美的程序猿中脱颖而出

    .code .container {
      font-size: 14px !important;
      padding: 15px !important;
    }
    
    .code .container code {
      font-family: "Lucida Console", Monaco, monospace !important;
    }
    
    .syntaxhighlighter table td.code .line {
      padding: 2px 1em !important;
    }
    
  • WordPress 在 localhost MAMP 执行时出现 500 错误的解决方案

    /Applications/MAMP/logs/php_error.log 下看错误,如果是:

    PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate x bytes) in /path/to/file on line n

    那么就去 /Applications/MAMP/bin/php/php5.3.6/conf/php.ini 里把 memory_limit 改为 64M 或更大即可

  • WordPress 3.1 成功部署/备忘录

    • 日文后台的语言包官方还没更新,中文包用的是 Dreamcolor 同学的 第三方 WordPress 中文包,已经放出了 3.1 甚至 dev 版的语言包,更新非常快,整体质量也比现在官方中文要好,推荐
    • 插件除了几个 multisite only 的插件在后台的菜单位置有所变动外,其他貌似都兼容
    • 现在 TwentyTen 可以正确去掉 header image 了,再配合 TwentyTen Kai,太帅了
    • 现在 postholic.com 在 admin 的带领下,运行在 nginx+PHP-FPM+APC 扩展上,跑了一周,效率非常高,而且也有了一套半自动化的部署脚本,加上 Amazon S3 的媒体文件备份,cron 30 分钟一次的全站 rsync,貌似这种低沉本的备份方式对于这样的站来说也是很安全的了
  • 从日文官方 WordPress 发现的好物:wp-multibyte-patch

    在日文官方的 WordPress 包中,发现了这么个好物:wp-multibyte-patch 。看名字也大体知道是干嘛的了,由日本人写的,粗略看了下,感觉是最全面和好用的针对非英文用户的补丁了,不需要任何设置,装上就可以用(不过也有参数可调),支持 WordPress multisite(丢到 mu-plugins 目录),作者比较低调,插件官网在 这里

    主要修正经典的摘要长度问题,效果参见本 blog 摘要,还有不少是针对日文的,比如同样搜索全角空格,修改 email 编码为 JIS 等,目前本人仍在间断的练习五十音中,日文好的自己去作者官网看吧

    我们在安装的时候,把 /ext/ja/config.php$wpmp_conf['mail_mode'] = 'JIS';JIS 改成 UTF-8 就行了

    更新:WordPress 3.2 后已经不存在此文件了。直接安装后激活即可,使用,想修改默认设置需要拷贝配置文件到 wp-content 目录下,具体可参考官方网站说明