I’m attempting to modify existing rewrite rules generated by WordPress in order to override the default rewrite rules generated.

I’m using the filter hook rewrite_rules_array to obtain an array of existing rewrite rules.

While sifting through the rewrite rules array, there are rewrite rules containing $ in the array value.

After replacing a set of array key/value pairs, PHP is interpreting the suffix text of the array value containing $ as a PHP variable.

For example: &feed=$matches[1].

When I’m done with my modifications and dump the array, everywhere with $matches[1] just appears blank.

My question is: How can I get &feed=$matches[1] to output as &feed=$matches[1] in my array value instead of outputting like &feed=?

Both my array keys and array values of the modified rewrite rules are contained within double quotes.

1 Answer
1

Wow I feel like a huge newblet. This is incredibly simple. Just escape it with a \.

"&feed=$matches[1]" should be "&feed=\$matches[1]".

EASY.

Leave a Reply

Your email address will not be published. Required fields are marked *