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
-3
votes
0answers
20 views

Can someone help me with a regex redirect in Yoast? [closed]

I've moved my categories and tags to a different URL. DOMAIN/tags/tag -> DOMAIN/t/tag DOMAIN/Categories/category -> DOMAIN/c/category I only now notice that the redirecting is not working anymore (...
0
votes
1answer
32 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 ...
0
votes
1answer
25 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
0
votes
0answers
18 views

How to pass the values of an array to another from bottom of the page to the top?

I know this is very simple and easy, but I am new to wordpress, php, and js. $classes = array(); array_push($classes, $match); foreach($classes as $names => $text ) { preg_match('/<strong ...
1
vote
3answers
25 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. $...
-1
votes
0answers
13 views

trying to highlight search results

I am trying to highlight search results of the content, but also only show the sentences where the search result terms show up. For instance, if I search for 'Test', there will be pages with the ...
0
votes
0answers
27 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*)&...
0
votes
0answers
21 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/...
0
votes
1answer
33 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, ...
1
vote
0answers
9 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....
1
vote
0answers
8 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 ...
1
vote
0answers
20 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 ...
0
votes
0answers
25 views

WP-CLI regex - search-replace match specific tags and any characters in between

I am using WP-CLI regex to replace specific tags and the content within the tags. Note that the content between the tags is dynamic so can change. I want to replace everything between [vc_row ...
1
vote
0answers
26 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. ...
0
votes
1answer
21 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 ...
0
votes
1answer
10 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-...
1
vote
0answers
28 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 ...
-1
votes
1answer
20 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: ' ...
0
votes
0answers
15 views

Add a prefix to the Wordpress Home directory

I have a code like the following, <?php function link_fn( $url ){ $lang = get_query_var('lang', false); if( $lang !== false ) { $url = $...
0
votes
0answers
23 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 ...
0
votes
1answer
132 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', '...
0
votes
1answer
312 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/ /(...
1
vote
1answer
25 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?
0
votes
0answers
29 views

How to replace old YouTube embed code in Wordpress

I'm moving an old site from ExpressionEngine to Wordpress. The blog has over 3000 posts and some of them have YouTube videos embedded in them using code like this: <object width="425" height="344"&...
2
votes
1answer
26 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 ...
3
votes
1answer
57 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 ...
0
votes
0answers
35 views

Filter to APPEND nofollow to rel

I am trying append nofollow to add external links. If a link does not have a rel attribute, rel="nofollow" will be added. If a link already has rel="nofollow" nothing will happen, and if a link has ...
0
votes
1answer
68 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 ...
0
votes
3answers
246 views

Is there a way to get wp_editor (tinymce) content?

I want to get the wp_editor (tinymce) content then find a sentence by specific word with regex. However, have no idea how to get the content When a post is published or updated, the function will get ...
0
votes
1answer
281 views

Redirect 301 of old urls to wordpress urls

I am migrating a website from vivvo cms to wordpress. Vivvo is using category pages like index.numberofthepage.html I want to redirect urls like using regex: https://www.example.com/mycats/index.200....
0
votes
1answer
202 views

Removing WP custom post type slug causes 404 error with blog posts when blog does not have front slug

I've tried this wonderful solution (solution below, original post here) for removing the slug from a custom post type, but unfortunately it causes a 404 error for blog posts when the blog slug is ...
0
votes
1answer
106 views

Redirect regex misbehaving when placeholder empty

I have the following 2 redirects active: /code-examples/(.*) -> /tutorials/android/$1/ and /code-examples/android/(.*) -> /tutorials/android/$1/ The first one has a higher position, so the ...
0
votes
1answer
476 views

Extract links from content

I'm looking for a solution to only display the links inside a string (my wysiwyg content) on my single page. First of all extract all my links, and replace each links content by the links title ...
0
votes
1answer
208 views

Get just subdirectory name from a multisite URL

I want to get just the subdirectory name from the network site, and I've gone through the codex and cannot find a function that already does this. I have come up with a few options to get to the ...
2
votes
1answer
459 views

How to remove “YEAR/MONTH/” from uploads URL & redirect old URL to the new form?

I have disabled "Organize my uploads into month and year-based folders". The links to my PDF files were of the form: https://www.example.com/wp-content/uploads/2018/03/document.pdf And now they are:...
0
votes
1answer
53 views

How to add rewrite rule for product compare page?

I'm trying to create a product compare feature where we can compare three products, Two products must be added while the third is optional. Trying to use the add_rewrite_rule to create a friendly URL ...
0
votes
1answer
363 views

Ideas how to search & replace post_content when string contains a newline?

I've previously been able to search & replace using the very helpful "Search & Replace" plugin for wordpress but now i've came across a problem i cannot solve. In table wp_posts i want to ...
0
votes
1answer
6k views

Replace Dash (-) and Underscore ( _ ) with Space

I want to replace dashes & underscores with space in this image file name: text1_text2-10212-etc_125.jpg (result of a plugin) My code is: $string = preg_replace('/[\-_]/',' ', $file['name']); I'...
0
votes
2answers
188 views

Redirect after Permalink change - What regex do I use?

I'm completely out of my league with regex stuff. I've seen a lot of examples for putting redirect code into the .htaccess file, but the default examples are mostly for changing away from dates. ...
0
votes
1answer
120 views

HTML regex convert to titlecase

I have a plugin with an option to use regular expression and find and replace the title post. I need to convert lots of titles with uppercase and lowcase letters to title case, but I have no idea ...
0
votes
1answer
375 views

Redirect non www to www using redirection plugin regex

I have a scenario where I can't get access to the .htaccess file (no ftp/ssh ) so im relying on the Redirection plugin to redirect. I have an issue where i need to redirect non-www to www, while ...
2
votes
1answer
3k views

Adding Wordpress API Endpoint With Multiple Parameters

So I understand for the most part how the wp rest controller works, what it is doing and why it is the best way to do it. The trouble I am having is wrapping my head around the regular expressions in ...
0
votes
1answer
85 views

How to return tags containing one, two or three exact and specific words using get_tags

I'm using get_tags (outside the loop) with the argument name__like to return tags containing one, two or three exact and specific words. I already tried (not working): $args = get_tags( 'orderby' =&...
0
votes
0answers
37 views

Wordpress add_rewrite_rule

Struggling to get this working, i've never used regex before or played with .htaccess so i'm struggling to get this work. Eventually what i want to try and achieve is: mywebsite/vehicle-info/bmw/s6/...
0
votes
1answer
1k views

Remove External Links from WordPress posts Using add_filter() in Theme functions.php

We have been searching high an low for a plugin, code sample or example of how to remove all external links at the theme filter level but can't seem to find anything online. We want to keep the ...
1
vote
1answer
372 views

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

I'm working on a website with two post types sharing several taxonomies & custom fields. I've developed a filtering functionality with pretty urls, and urls for now works this way: 1) I've ...
1
vote
1answer
124 views

optimize wordpress rewrite rule regex

i have this codes in my wordpress plugin to add custom url rewrites: add_action('init', function() { add_rewrite_rule( '^cities/(.*)/browse/(.*)/(.*)/(.*)/(.*)', 'index.php?city_name=$...
0
votes
1answer
138 views

Call Shortcode Attribute Value within another function

Please anyone with an idea of how I can extract some values of this shortcode attributes and use it within another function. How the code looks like: function myVal($attr, $content = null) { ...
0
votes
1answer
43 views

Prevent WordPress from putting <p> around specific element

On my WordPress page I sometimes have the issues, that WordPress puts tags around elements, where I don't want them. For instance, I have this "invisible anchor" on many pages: <a class="anchor" ...
2
votes
1answer
65 views

Remove all categories from URL

This is the original I need to modify: https://example.com/actualites-cyclisme/criterium-du-dauphine/5115-dauphine-libere-le-parcours-devoile-lalpe-dhuez-fait-son-retour These are the things I have ...