2

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

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.