Questions tagged [regex]

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).

Filter by
Sorted by
Tagged with
0 votes
0 answers
24 views

What's the WordPress way to get custom HTML for child pages list (with a second relative link)? Currently running regex over wp_list_pages() output

I use wp_list_pages() to output all the child pages of the currently viewed page. This works well enough but I wanted to add the comment feed URL with an icon next to each child page. My solution was ...
Matthew Brown aka Lord Matt's user avatar
0 votes
1 answer
32 views

Replace image with its alt text?

I have a WordPress post with lots of inline HTML images. I want to output my HTML in such a way that the existing: <p>Here's my cat: <img src="example.jpg" alt="A photo of ...
Terence Eden's user avatar
1 vote
1 answer
97 views

Why is this line of code Wrong in every Wordpress .Htaccess security article?

The following line of code (RegEx) is partly wrong in every Wordpress .Htaccess hardening article I've seen. Why is that? <FilesMatch "^.*(error_log|wp-config\.php|php.ini|\.[hH][tT][aApP].*)$&...
Yahya Tarjuman's user avatar
0 votes
1 answer
157 views

Adding or replacing image size

I have a lot posts converted from classic editor to block editor and in the process, some image blocks (or all) have missing sizeSlug attribute, which editor interpretes as thumbnail size. However, I ...
Lovor's user avatar
  • 901
0 votes
0 answers
19 views

How to combine nearly identical custom rewrite rules for WordPress

I have 22 rewrite rules in my functions.php. I was wondering if it is possible to combine some of the nearly identical rewrite rules. Combining identical rewrite rules for different PAGES: '^videos/...
Philip's user avatar
  • 103
0 votes
1 answer
19 views

Redirect loops in Bing holding my sites back

Have been running HTTPS for a while and everything is good. I was looking at the webmaster tools on Bing and it shows some redirect loops going on. I see thousands of them. I've looked at all the ...
The King Repairs's user avatar
0 votes
0 answers
119 views

Standard Regex syntax doesn't work in WordPress rewrite rule

I've run into a regex issue while adding a rewrite rule into a Wordpress plugin. This blog has been helpful and the redirect works correctly after following this: https://brightminded.com/blog/...
AutoBaker's user avatar
  • 151
1 vote
2 answers
161 views

How to cut a section of a URL from a string with a regular expression?

I am pulling a response from an API using PHP to display a list of content on my WordPress website from an external service. The way they have their API set up, I need to create a loop that checks if ...
NathanThreelines's user avatar
0 votes
1 answer
118 views

Meta query with string NOT ending like pattern

I need to find all posts that do NOT have in a specific meta key values ending with ".mp3". I know that I can use REGEXP for this, but I can't figure out how to do it. My code now returns ...
Yuri's user avatar
  • 1,111
0 votes
0 answers
37 views

Multisite image URLs incorrect in editor

I've been driving myself nuts with this one, so I'm hoping someone might be able to help. I have a Multisite with the latest WordPress version set to subfolders. The issue I am experiencing is with ...
Danny Santoro's user avatar
0 votes
1 answer
124 views

Regex for pdf's - Old .asp Site folder structure to new WordPress Media Folder(s)

I am in the process of rebuilding a site in WordPress that was built 20+ years ago on a .asp framework (think Dreamweaver) and am having a bit of an issue creating a RegEx for documents (.pdf, .doc, ...
Whispar Design's user avatar
0 votes
0 answers
283 views

Dynamic URL Rewrite for Custom

I have a custom post type called Hotels which I woud like to link to using the below url structure: /{country}/{state}/{hotel-name} I am fetching and inserting posts dynamically, so I do not know the ...
user2868900's user avatar
0 votes
1 answer
83 views

REGEXP_REPLACE in post_contet

So, basically, I want to remove trailing slashes from specific domain urls. For example: https://www.example.com/here/postname/ into https://www.example.com/here/postname I have 10.4.21-MariaDB which ...
Ivana Kruljac's user avatar
0 votes
0 answers
823 views

How to add custom regex validation to WPForms password field

I'm using WPForms Pro and I'd like to add custom requirements to the password field on a form. I know that the password field has a password strength requirement setting, but I have specific rules I'd ...
Sidewinder's user avatar
0 votes
0 answers
135 views

Block internal search queries with pre_get_posts and regex rules

This relates to my previous question: Internal search spam (UPD: I no longer use Ivory Search) The closest question I found: Block search keywords As I understood, I need to use pre_get_posts, but I ...
Terry's user avatar
  • 1
0 votes
1 answer
215 views

add_rewrite_rule with optional parameters

Using add_rewrite_rule() to handle things like this for the custom post type "catalogs", page name "cars": /catalogs/cars/ /catalogs/cars/p1/ /catalogs/cars/p1/p2/ /catalogs/cars/...
Mads's user avatar
  • 1
0 votes
0 answers
32 views

Problem with Wordpress permalinks

We have set our permalinks so that it displays like this: example.com/iphones/ for categories and example.com/iphones/iphone-11-Pro for the products. The problem that the old native URLs of ...
B n's user avatar
  • 1
0 votes
2 answers
4k views

Register GET REST API route with multiple parameters

I'm trying to register a GET REST API route with multiple parameters with the following code: register_rest_route( 'myplugin/v1', '/posts/?number=(?P<number>[\d]+)&amp;offset=(?P<offset&...
leemon's user avatar
  • 1,898
1 vote
1 answer
1k views

htaccess redirect - replace special character

In my previous post, I asked about how to 301 redirect all .com/language/X URLs to .com/members/?members_search=X using htaccess. Thankfully I got help, and the solution was RewriteRule ^language/(.*)...
Jennifer's user avatar
0 votes
1 answer
392 views

How to redirect Webp files?

I was using all images as webp files for performance, however I've stopped using and deleted them (only .webp files) all from FTP. Now having problems with 404 errors. I would like to redirect all ....
Aslan's user avatar
  • 13
1 vote
1 answer
708 views

Issue with htaccess redirection in WP Multisite

My site structure is main site example.com and two subfolders sites /es/ and /en/ example.com redirects => example.com/es/ and example.com/en/ is the English version. What is wrong? The following: ...
Irene's user avatar
  • 23
0 votes
0 answers
27 views

Media Library Cleanup A Thought Exercise

I have a site with roughly 1200 posts. Each post has a featured image and a few placed images in the content. Over the years we have had a bad habit of using the WordPress image editor to crop and ...
J. Patrick Moran's user avatar
1 vote
0 answers
23 views

Displaying Post with Custom URL with RewriteRule or add_rewrite_rule

I'm having what I believe is a common issue: I want to display a post with a slug with a custom URL, in my case, this is the format /resources/{state}/{city}/{location}/ which would match a post slug ...
Evan Rose's user avatar
0 votes
1 answer
585 views

preg_replace regex problem

I'm trying to alter the content of an email generated by a plugin, removing a lengthy section that starts with <p> NOTE: (the space is actually a tab) and ending with /</a><br /> (...
Jim Worrall's user avatar
0 votes
1 answer
18 views

ACF - Eliminate unnecessary data and print

In ACF, the_field('battery'); outputs as follows : Battery : Sony Rechargeable Ni-MH 2200 mAh battery or Battery : Energizer AA Rechargeable Batteries 2300 mAh NiMH How can i achieve this (showing ...
seezar's user avatar
  • 5
0 votes
2 answers
231 views

Adding span tags to post titles using regex

My basic titles are something like Part One: Part Two And I'm trying to end up with something like this using the colon as what I find in the regex: <span class="one-class">Part One:&...
HopefullCoder's user avatar
0 votes
1 answer
217 views

Rewrite rule regex help required

Hoping you can help with this... WE have a 'serivces' custom post type that allows a 'service' to have a parent 'service'. Our custom rewrite rule works for top-level services but not child services. ...
Will Fairhurst's user avatar
0 votes
0 answers
138 views

Remove Custom HTML Posts Using Regex

I want to delete the custom HTML that is in all posts. It is impossible for me to edit one post at a time because there have been many posts that I have published. I want to delete it using Regex via ...
R.M. Reza's user avatar
  • 141
-2 votes
1 answer
170 views

preg_replace specific Text to small latter strtolower [closed]

Please i need to replace link with capital letter to small letter using wp function E.g let every text after /get/ be replace with small letter. <a href="https://stackexchange.com/get/ASK-Question"...
XATA's user avatar
  • 67
0 votes
0 answers
195 views

search and replace using regex

Hello please I want to search and replace word after /check/ and make it to be permalink sanitized. i.e https://example.com/check/Dav,ido Song/ => with https://example.com/dav-ido-song/ https://...
XATA's user avatar
  • 67
0 votes
0 answers
129 views

Regexes allow only [a-z][A-Z][0-9] and -

please I am a novice when it comes to regexes, Using search and replace, how can i allow only a-z, A-Z, 0.9 and - on a link, E.g https://example.com/dav,ido song/ will be replaced with https://...
XATA's user avatar
  • 67
0 votes
0 answers
267 views

WP_Query Regexp whitespace and end of string

Hello I'm using ACL and I have trouble with REGEXP. I tried many ways but somehow it doesn't work. The meta-field is a ACL-Textarea. I need to search after searchword. After that word there may ...
Floh's user avatar
  • 1
0 votes
1 answer
20 views

Need help with regex

I have this definiton to add a query var: add_filter( 'query_vars', 'add_reg_query_vars', 10, 1 ); function add_reg_query_vars($vars) { $vars[] = 'seminar'; // return $vars; } and this ...
Joe Lipps's user avatar
0 votes
1 answer
51 views

SEO friendly query vars

I have an issue with a PHP form and the query vars it generates to fetch certain posts. An example of a generated URL could look like this: siteurl/properties/?state=georgia&type=industrial The ...
Sergi's user avatar
  • 260
0 votes
0 answers
451 views

Redirect files in uploads directory if WordPress user not logged in

I would like to redirect all of the following urls if a WordPress user is not logged in (or WordPress cookie is set) using .htaccess. https://example.com/wp-content/uploads/sample_pdf https://...
Dee Bryant's user avatar
1 vote
0 answers
755 views

Regex expression for redirecting image URLs to another folder

I have changed the upload folder to a folder called "images" in the root folder by entering define('UPLOADS', 'images'); inside wp-config.php file. My Media settings had the images organized into ...
quantum_leap's user avatar
2 votes
2 answers
334 views

Register Embed Handler for Padlet.com

I'm trying and failing to register an embed code for content from padlet.com (strangely it's supported in WP.com but not WP.org). A URL like https://padlet.com/cogdogblog/aos9fosbbwk4 should embed ...
cogdog's user avatar
  • 141
0 votes
1 answer
3k views

How to get different html tags from the content using regex?

I am trying to get different html tags from a single post and display them as nested accordion. I have quite accomplished. the only problem I have is that. When I try to show all the p tags content ...
Ashur's user avatar
  • 23
1 vote
1 answer
3k views

how to remove colon and white space in a string by php

How can to remove colon's and white space's in a string by php. .e.g: The Godfather: Part II
Brock_s34's user avatar
1 vote
3 answers
3k views

How to use a variable as a className inside preg_match_all parameters?

I am using regular expression to get the text inside a single p tag targeting its class. the problem is I want to use a php variable as class name and use a loop to change the class name each time. $...
Ashur's user avatar
  • 23
0 votes
0 answers
29 views

Wordpress Own Rewrite Rules

i am trying to rewrite a URL with the following code in functions.php add_action('init', function() { add_rewrite_rule('/agbz\/(\w*)\/\?page=(\w*)&memberID=([a-z]{1}\d*)&land=(\w*)&...
nitroox's user avatar
1 vote
0 answers
36 views

Regex with a possible hyphen

I am working on a site for cars. I wrote a regex which worked, up until the point where brands are separated by a hyphen. These are 2 examples I want to match: class-s/ford-shelby-gt350r class-s/...
Beee's user avatar
  • 563
0 votes
1 answer
641 views

How to add no follow to specific links?

I have some cloaking affiliate links to which I would like to add the attributes of nofollow. However, I'm looking for a way in coding that will allow me to target links that contain specific string, ...
marouane91's user avatar
1 vote
0 answers
17 views

Regex with HttAccess

I am trying to use a regex redirect for media, we had them on a cdn but we are moving them back to wordpress. https://res.cloudinary.com/website/image/upload/v........../website/images/ https://www....
dval21's user avatar
  • 11
1 vote
0 answers
15 views

Regex redirect rule for missing part of the path

i want to have a redirect rule for: before: /ratgeber/one/two/three/, after: /one/two/three/ or before: /ratgeber/one/two/three/four, after: /one/two/three/four/ So i just only want to redirect to ...
Sporty T's user avatar
1 vote
0 answers
50 views

Remove shortcodes that are different (but same pattern) in each post

I have unused shortcodes in my posts like the following: [wp-imageflow2 dir=NokiaN868MP176] [wp-imageflow2 dir=Nokia6303classic97] [wp-imageflow2 dir=LGOptimus3DCubeSU87026] How do I remove them ...
sonya's user avatar
  • 11
1 vote
0 answers
43 views

Applying A Category to Existing Posts Where Page Title Matches Regex

I have a whole bunch of posts that I need to add a category to (too many to do via Bulk Actions). They all follow a predictable/consistent post title naming structure that could be matched via regex. ...
Drewdavid's user avatar
  • 199
0 votes
1 answer
127 views

enqueue script with get_shortcode_regex

I try to optimize a bit and i want to load some shortcodes only if they are found in global $post Unfortunately its not working, the script is not loaded when i open a page which contains the ...
LovinQuaQua's user avatar
0 votes
1 answer
15 views

Strange behaviour of REGEX in a Wordpress filter (trying to suppress emtpy paragraphs)

I've been trying to add a filter in Wordpress to suppress empty paragraphs. I found a number of alternatives online (here is one of them https://gomakethings.com/remove-empty-paragraphs-added-by-...
Alex's user avatar
  • 1
1 vote
0 answers
101 views

Preg Match All doesn't Allow echo first character for Wordpress Taxonomy Tags

I have been working on a code, that finds particular words from my content and converts them to wordpress Taxonomy Tags. I want to prefix them with a '#' symbol... But somehow it doesn't work This is ...
Aditya Agarwal's user avatar