Regular expressions (abbreviated regex) are terms that define a search pattern to focus on a specific part of a string for a specific purpose (e.g. to find/replace a word).

learn more… | top users | synonyms

0
votes
2answers
75 views

How to handle a post before publishing?

I want to do a regex match to each post before it gets published, and if the regex fails to match, delete the post entirely, what hook should I use?
2
votes
1answer
237 views

Regex in add_rewrite_tag not accepting OR operators?

I am trying to add a custom field to the post permalinks by using a combo of add_rewrite_tag and applying a post_link filter. What I am aiming for is something like this: http://example.com/%...
1
vote
1answer
157 views

Processing shortcodes in groups (separated by line breaks)?

The Project I'm working on a plugin to resize and embed rows of images using shortcodes that will be converted into <img> tags. In most cases there will be multiple images per row, and the ...
0
votes
1answer
19 views

How to fix old embeded iframes with WP-CLI search-replace

I want to change this: <iframe width="850" height="478" src="https://www.youtube.com/embed/4zH9Zca1vRM" frameborder="0" allowfullscreen></iframe> For this: https://www.youtu.be/...
0
votes
1answer
21 views

Redirect Loop in Regex Moving to HTTPS

First, this site has been running on HTTPS for over 6 months with a green address bar and all. It was only recently I was reading on Bing Webmaster Tools that redirect loops were a problem on this ...
0
votes
1answer
93 views

Using preg_replace() with the_content filter

I am trying to append a php query to the end of links from my website to a sponsor site using the_content filter and preg_replace(). I have tested my regex expression on regexr.com and it works also ...
0
votes
1answer
53 views

RegExp to EXCLUDE strip HTML (FOR SOMME) comments

I'm using this function to remove HTML comments from my code to save loading time: // Remove unwanted HTML comments function remove_html_comments($content = '') { return preg_replace('/<!--(.|\s)*?...
0
votes
1answer
53 views

regEx wp core file

I have an issue with the way WordPress handles creating a page anchor. The page anchor button is already defined in the WordPress TinyMCE code.. and can be added using either the Ultimate Tinymce or ...
0
votes
1answer
347 views

Rewrite Rule & Regex - Extract 'cat-name' and 'page-number' from http://domain.com/custom-post-type/category/cat-name/page/page-number

I have an URL formatted so: http://domain.com/custom-post-type/category/cat-name/page/page-number I need to extract: cat-name and page-number So that in my functions.php, I can create the custom ...
0
votes
1answer
171 views

Avoid too long words in a post title, post content or comment but only if its not a url

I want to prevent users from posting things like "aaaadfgdfgsdfgdaaaadsfgsdfgaaasdfgdfaaadfgsdfgaaaaaaaajahkjhkahkkjkjhaa..." which would not only be annoying but would certainly break the content div ...
1
vote
0answers
40 views

Custom Post Type relationship with hierarchical parent and child permalinks

Trying to get my permalink and url structures to behave nicely. I have a Custom Post Type called Diseases. This post type is hierarchical with parent and child relationships. I have another CPT ...
1
vote
0answers
18 views

Removed custom post type slug but not working for child pages

There are many discussions going about to handle child pages for custom post types were the custom post type slug has been removed. This results into an 404 because Wordpress can't match a valid regex....
1
vote
0answers
97 views

Correct regex for Nginx FastCGI cache?

https://codex.wordpress.org/Nginx#Nginx_fastcgi_cache currently has the following regex: # Don't cache uris containing the following segments if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|...
1
vote
0answers
545 views

Compare meta_query with a Regular Expression and do a less-than operation on it

I have the problem that my client is using a theme which stores options of items in a serialized way in the post_meta table. I already found out that this is not the best way to save values ...
1
vote
0answers
91 views

Regex to turn embedded images in to attachments

I've got a blog that has all images embedded in each post rather than a thumbnail linking to an attachment page which is what I'd like. I understand from this question that no plugin (like Regenerate ...
1
vote
0answers
120 views

What add_rewrite_tag()'s RegEx matches against?

I'm trying to figure out wether I can specify the position of the string to match (i.e. immediately after the domain) to reduce the chances of matching something else, but I don't even know what the ...
1
vote
0answers
195 views

Struggling with add_rewrite_rule

I've read this: Wordpress redirection to get url friendly That led me to this: 1) wp.tutsplus.com/tutorials/creative-coding/the-rewrite-api-the-basics/ 2) wp.tutsplus.com/tutorials/creative-coding/...
0
votes
0answers
26 views

wordpress rewrite and keep url for page

I am using the rewrite api with the following that works... add_rewrite_rule( '^ch/(\d+)', 'index.php?p=$matches[1]', 'top' ); The idea is that the ch identifies it as Chinese and the ...
0
votes
0answers
25 views

How to ignore further page child path?

We are desperately looking for a way to create a page that accepts parameters, just like: example.com/mypage/?key=value but... without the ordinary query string. Instead, we wish to use the ...
0
votes
0answers
41 views

How to unwrap/separate Html tags in pages?

I have around 300 pages with some of them having wrong HTML formatting that I have to fix. I want to: Separate the H1 tag from the inner tags. Moving the TITLE (found in span) to H1. Get rid of the ...
0
votes
0answers
19 views

Help with complex WP Regex express for .htaccess

I managed to do a proper regex redirect for one of our 10 year old sites which has gone through a series of pretty permalink changes over the years, but now having trouble sorting this out for two ...
0
votes
0answers
67 views

Why is my script's regex having its backslash removed?

One of my company's child themes requires customization. I am customizing using jQuery and have noticed in my function's regex (function lives in the "scripts" section of "Pages"--->My Page) that ...
0
votes
0answers
30 views

How to rediect old canonical links to new

I recently noticed wordpress 4.x is not redirecting old canonical links to the new format and gives a 404 error in crawl and where ever referenced. I have checked this Yoast to get some help on the ...
0
votes
0answers
62 views

Regex replace on the fly

Heres the example content on all my post <img width="550" height="486" src="http://www.xyz.com/wp-content/uploads/2014/12/-550x550-550x486.jpg" /> <img width="760" height="486" src="http://...
0
votes
0answers
99 views

Add class to all parent elements inside the_content

Is there a way to add a class to all parent elements inside the_content? My problem is I'm using this kind of css selector: .post_content>* {margin-bottom:10px;} This is to due with mostly ...