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
21 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 ...
user avatar
0 votes
0 answers
30 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 ...
user avatar
0 votes
0 answers
43 views

Custom taxonomy terms as children of multiple custom post types

I'm about to start a part of my project that I've been putting off for too long. I'm not looking for code, I'm looking for confirmation that I'm on the right track and any advice Stackexchange may ...
user avatar
0 votes
0 answers
9 views

WordPress: Highlight search result exact matches

found this neat code to highlight search terms. My problem with the code is that it does not prioritize exact matches and it highlights words within other words. So searching for "in my hometown&...
user avatar
0 votes
0 answers
46 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 ...
user avatar
  • 1
0 votes
0 answers
12 views

Restrict comments with regular expression

I want to prevent users to write email addresses in comments. I know we can restrict words in wp-admin > Settings > Discussion > Disallowed Comment Keys. but can we add a RegExp such ([a-zA-...
user avatar
  • 3
0 votes
1 answer
37 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/...
user avatar
  • 1
0 votes
0 answers
120 views

Contact form 7: Prevent input html tag in text field

How to create validation in contact form 7 to prevent user input HTML tag like ... or , also to prevent scripts like $(dummy){}. I create validation to prevent URL and non Latin characters, how I ...
user avatar
0 votes
0 answers
31 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 ...
user avatar
  • 1
0 votes
2 answers
2k 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&...
user avatar
  • 1,607
1 vote
1 answer
544 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/(.*)...
user avatar
0 votes
1 answer
116 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 ....
user avatar
  • 11
1 vote
1 answer
389 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: ...
user avatar
  • 23
0 votes
0 answers
18 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 ...
user avatar
1 vote
0 answers
20 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 ...
user avatar
0 votes
1 answer
248 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 /> (...
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 ...
user avatar
  • 5
0 votes
2 answers
112 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:&...
user avatar
0 votes
1 answer
122 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. ...
user avatar
0 votes
0 answers
78 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 ...
user avatar
  • 141
-2 votes
1 answer
45 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"...
user avatar
  • 67
0 votes
0 answers
62 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://...
user avatar
  • 67
0 votes
0 answers
52 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://...
user avatar
  • 67
0 votes
0 answers
123 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 ...
user avatar
  • 1
0 votes
1 answer
15 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 ...
user avatar
0 votes
1 answer
33 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 ...
user avatar
  • 260
0 votes
0 answers
197 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://...
user avatar
1 vote
0 answers
447 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 ...
user avatar
2 votes
2 answers
278 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 ...
user avatar
  • 141
0 votes
1 answer
2k 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 ...
user avatar
  • 23
0 votes
1 answer
2k 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
user avatar
1 vote
3 answers
2k 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. $...
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*)&...
user avatar
1 vote
0 answers
34 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/...
user avatar
  • 553
0 votes
1 answer
378 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, ...
user avatar
1 vote
0 answers
16 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....
user avatar
  • 11
1 vote
0 answers
13 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 ...
user avatar
1 vote
0 answers
37 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 ...
user avatar
  • 11
1 vote
0 answers
36 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. ...
user avatar
  • 169
0 votes
1 answer
73 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 ...
user avatar
0 votes
1 answer
13 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-...
user avatar
  • 1
1 vote
0 answers
67 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 ...
user avatar
-1 votes
1 answer
164 views

Apostrophes replaced by &#39;

I use a plugin for automatic posting of articles on social networks, and when I send an article on Facebook or Twitter from my website, the apostrophes of my articles are replaced by this: ' ...
user avatar
0 votes
0 answers
71 views

How to wrap pattern-matches from the_content in [wiki]-shortcode tags

I'm working on a function to wrap word-matches* in [wiki]-shortcode tags. I suspect the best method is to use add_filter() on the_content, and parse using RegEx in preg_replace_callback_array(), but ...
user avatar
0 votes
1 answer
730 views

rest api endpoint - accept diacritic characters

I am trying to register a custom endpoint, which will accept diacritic (accent) characters, so that I may search it in french. This is what I have tried: register_rest_route('events/v1', '...
user avatar
0 votes
1 answer
3k views

php preg_match with multiple patterns

I am trying to combine two preg_match patterns separate with ,|,. /blog\/page\/[0-9]+\/?$/ with /tag\/ skip in /blog/page/ and /tag/ /page\/[0-9]+\/?$/ with /[0-9]+\/?$/ ex. /page/2/ and only /2/ /(...
user avatar
1 vote
1 answer
1k views

What's the "?P<tag>" register rest api construct, what is for and where to find official docs?

I noticed that often in register_rest_routes, are used regexp like ?P<lang>, ?P<category_id>\d+ and so on, but I guess it's not standard regexp syntax. What exactly does it do?
user avatar
2 votes
1 answer
85 views

Remove all table widths from editor content

When I paste a table into the WordPress editor, I always get widths like <td width="232">. I want to remove all widths when tables are added to the editor. If it was regex, I would write ...
user avatar
  • 23
3 votes
1 answer
211 views

Custom post type permalink changing itself every other change

I have created a parent > child > grandchild structure. (Courses > Series > Episodes). I have created the below code which updates the urls for each of the custom post types so that I can have the ...
user avatar
  • 163
0 votes
1 answer
434 views

Wordpress add_rewrite_rule with 2 variables

I need to create a rewrite rule that accepts 2 variables. I'm very new to this and am not sure If I'm even on the right track. If there is a better solution to what I'm trying to achieve, I'm open for ...
user avatar