LoginSignup
1

Real-Time Find and Replace で置換されないときの対処法

Last updated at Posted at 2024-03-07

Real-Time Find and Replaceプラグインでの置換が適用されないときの対象方法を紹介します。

※ これは2016-09-26に個人ブログで公開した記事を移植し、CC0-1.0で提供しています。情報は古い可能性があります。

プラグインの概要

WordPressで表示される公開ページの置換、正規表現置換ができるプラグインです。

置換されない…

Autoptimizeプラグインで生成されたjs、cssファイルのURLを変更するために使用したのですが、置換作業がうまくいきませんでした。

原因

AutoptimizeプラグインやReal-Time Find and Replaceプラグインも template_redirect フックを利用していました。優先順位がどちらも同一であったため、名前順でAutoptimizeプラグインの出力のバッファリングが先に開始されてしまったことが原因です。

対処

Real-Time Find and Replaceプラグインの出力のバッファリングの優先順位をあげます。「real-time-find-and-replace.php」の最終行を次のように変更します。-1は場合によって変更してください。Autoptimizeは0でしたので、-1を設定しました。

- add_action( 'template_redirect', 'far_template_redirect');
+ add_action( 'template_redirect', 'far_template_redirect' ,-1);

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1