Issue with htaccess redirection in WP Multisite

Every URL that has example.com/<non-existent-page> redirects to the main page: example.com/es/. This is presumably being done by WordPress itself, as there is nothing in what you’ve posted (in .htaccess) that is doing this. You probably need to add an additional “wildcard” redirect to redirect /<anything> (except for /es and /en) to /es/<anything>. For example: RewriteCond … Read more

htaccess redirect – replace special character

Try it like this, replacing your existing redirect (which is now the 2nd rule below): # Repeatedly replace all hyphens with %20 – internally RewriteRule ^language/(.*)-(.*) language/$1\%20$2 [N,DPI] # Redirect to query string RewriteRule ^language/(.*) /members/?members_search=$1 [NE,R=301,L] This achieves the hyphen replacement and redirect to query string in just 1 external redirect. No additional redirect … Read more

404 regular-expression advice needed

It seems you can have both post ID’s and numbers in the page slug. So my-post-2 could be my-post with post ID 2 or my-post-2 with no post ID. In theory there is no way to solve this, but in practice maybe we can assume that you won’t have ten similar slugs, so the slug … Read more

get_shortcode_regex() only matches first shortcode

From PHP docs (emphasis mine): preg_match() returns the number of times pattern matches. That will be either 0 times (no match) or 1 time because preg_match() will stop searching after the first match. preg_match_all() on the contrary will continue until it reaches the end of subject.

Regex to Remove File Extension

Let’s see, this should do the trick then: RewriteCond %{REQUEST_URI} \.html$ RewriteCond %{REQUEST_URI} !^/specialfolder/ RewriteRule (.*)\.html http://www.example.com$1 [R=301,L]

preg_replace and comment_form_defaults

You can use regex anywhere you have a string to manipulate. That is basic PHP. There is nothing special about WordPress that changes that. But why use regex when there are other options? As much fun as it is, regex is tricky and easy to get wrong, and there is significant overhead to using it. … Read more

Why won’t my preg_replace work with content_save_pre?

I copied your code to a file in my home directory on my Ubuntu box, removed the weird character that @s_ha_dum noticed, and ran it. It worked as I’d expect. Code: <?php function get_the_post_imgs($oldPostContent) { $newPostContent = $oldPostContent; $newPostContent = preg_replace_callback( “/<img.*src=[\”‘]([^\”‘]*)[\”‘].*>/i”, // pattern to match to (i.e the contents of an <img src=”https://wordpress.stackexchange.com/questions/140017/…” /> … Read more

Get shortcode attribute outside of WordPress

Don’t try to parse the shortcodes and then regex the HTML. Use get_shortcode_regex() to parse the raw post content: $content = $content_post->post_content; preg_match_all(“/$pattern/”,$content,$matches); Then crawl $matches to find your shortcode data. Use shortcode_parse_atts($matches[3][0]) (note $matches[3][0] to give the first element within the matched shortcode’s attributes) to pull apart the attribute string. Reference: https://wordpress.stackexchange.com/a/73461/21376

Rewrite rule to prettify two $_GET variables while in a new endpoint from a page

I think you are using endpoints incorrectly. When a endopoint is created, a new rewrite rule is created using a query var with the same name of the endpoint; its value is taken from the string that follows the endpoint definition. So, if you register “my-endpoint” and build this URL: /page-slug/my-endpoint/123/some-string The endpoint is passed … Read more

Conditional regex in add_rewrite_rule() for specific query filters & pagination

I’ve managed to workaround the problem. He’re the solution for further reference. 1) I have only 1 query var now: function return_vars( $vars ) { $vars[] = ‘filters’; return $vars; } 2) My rewrite rules changed to: add_rewrite_rule( ‘my-base/filters/([^\/]*)/([^&]*)/page/([0-9]{1,})/?’, ‘index.php?post_type=$matches[1]&filters=$matches[2]&paged=$matches[3]’, ‘top’); add_rewrite_rule( ‘my-base/filters/([^\/]*)/([^&]*)/?’, ‘index.php?post_type=$matches[1]&filters=$matches[2]’, ‘top’); Rule 1: handles pagination Rule 2: handles main page only … Read more