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
0answers
6 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 ...
1
vote
0answers
10 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 ...
2
votes
1answer
31 views

Get original image from thumbnail URL

I am using a method to find the first image included in a post's content to display as it's thumbnail (a little hacky, but it works). However, some authors add small sized images, and since this ...
3
votes
1answer
51 views

Correct regex for wp_embed_register_handler

THE GOAL I'm trying to parse a url and convert it to an embedded video player in my post's content but I think my regEx is off or I'm not creating a provider correctly. THE CODE Here is what I have ...
0
votes
1answer
23 views

How can I reduce the number of rewrite rules?

I'm building a robust filtering system for my WordPress site, and I really want to have pretty permalinks for the resulting URLs. But because I'm offering a large amount of different filtering ...
0
votes
1answer
34 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 ...
1
vote
1answer
58 views

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

I'm trying to create a permalink rule which is a few levels deep. I have a basic page /page-slug/ - I'm appending to it a new endpoint: /page-slug/my-endpoint/ - from here I need to nest one id and ...
1
vote
1answer
41 views

Modify Image Source With The_Content Filter?

I'm very inexperienced with regex, however I'm trying to create a function that filters through the_content() and get_the_content() in order to modify the SRC of all images. The intended purpose ...
0
votes
1answer
44 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 ...
0
votes
0answers
18 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
1answer
21 views

Can an RSS item be altered with a hook?

I would like to alter the content of each item in a site's RSS feed with a regular expression. The rss2_item hook is close but it is run just after the item has been output, so is only really useful ...
1
vote
1answer
58 views

Adding regex filter to feedwordpress

I'm trying to write a plugin for Feedwordpress that filters html from the incoming feeds. So far I have managed to hook it to the right place, but the function completely wipes all content (and it ...
0
votes
0answers
46 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
1answer
73 views

Preg_Match(): compilation failed unknown property name

I'm having a problem with a wordpress theme I bought but their support is terrible. On every post page, I receive this error: Warning: preg_match(): Compilation failed: unknown property name after ...
0
votes
2answers
52 views

add_rewrite_rule isnt working, not getting added to rules array, why?

I'm trying to add a new rewrite rule but it doesn't seem to be getting added to the array and it certainly isn't working. I'm trying to get this URL, dult.dev/lists/games/destiny, to take me from a ...
1
vote
0answers
77 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 ~* ...
1
vote
1answer
138 views

Get shortcode attribute outside of Wordpress

Is there a clean way to get a shortcode's attribute value outside of Wordpress's default behaviour? I am working on a single script outside a Wordpress installation, where I only do ...
0
votes
0answers
25 views

Redirection plugin and Regex in “Search”

I'm tried to search a way to make a redirect 301 from the search box of my old site to my new site with Redirection plugin, for example: Old - /?s=(.*) Target - http://www.example.com/?s=$1 but ...
0
votes
0answers
27 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
1answer
41 views

How can I globally italicize certain text?

I have a large WordPress site, and I want to take a certain text phrase and italicize all instances of that phrase, for all pages. Does anyone know of a plugin that can do this? Particularly, for ...
0
votes
1answer
91 views

Shortcode and whitespace formatting problem

I'm having a problem with shortcodes on a website, currently you enter a shortcode in the post edit screen like the following: [tab name=Itinerary] This will output a tab such as: However as ...
1
vote
0answers
412 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 ...
0
votes
1answer
860 views

Extract attribute values from every shortcode in post

I have multiple shortcodes in the post: [section title="first"] [section title="second"] [section title="third"] I want to extract all title values (i.e first, second, third) from external ...
0
votes
0answers
57 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" ...
0
votes
1answer
607 views

Getting shortcode attribute values and shortcode content with JavaScript regex

This is an example shortcode: [boutique_banner title="Loyalty Program:" link="More" linkhref="/"]Earn 1 point for every $5 spent[/boutique_banner] I have created a custom mce view to display this ...
0
votes
1answer
374 views

How to dequeue a stylesheet by src, not handle?

I'm trying to develop a Wordpress plugin that will dequeue/deregister Font Awesome stylesheets added to a theme by certain plugins that users may install, if the theme already make use of Font ...
0
votes
1answer
153 views

Wrapping shortcodes in another shortcode

I'd like to wrap existing shortcodes in post content inside a new shortcode that I'm adding to my plugin. The existing content looks like this: Some text - could be <span>HTML</span> or ...
1
vote
1answer
209 views

Why won't my preg_replace work with content_save_pre?

I've written a filter function to replace all image URLs in a post with URL from the Uploads directory of my site. However, when using the content_save_pre, filter it won't actually work - but if I ...
1
vote
1answer
174 views

Custom rewrite_rules - only pass numbers and not alphabetic characters

I'm trying to add a rewrite rule to pass a var to a custom page template. For some weird reason it only excepts numbers in the variables, when I type in characters other then number it directs to ...
0
votes
2answers
486 views

What is the structure of the “Featured Image” field in the DB?

On a WP install with about 1400 images and the Media Tools 1.1 plugin, I ran both "Import External and Set Featured Image" and "Set Featured Image". But the featured images functionality didnt work, ...
0
votes
0answers
97 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 ...
2
votes
1answer
436 views

Allowing shortcodes inside attributes

I want to do a Wikipedia-like infobox for some articles on a WP site. I guess the most logical thing to do it is to use a custom shortcode—one that returns a table-like markup with a fixed order of ...
0
votes
1answer
602 views

Adding elements to wp_list_pages (within <li>, but before <a>)

I'm working on my first wordpress theme and I'm running into some trouble. I'd like to add an extra div (which I'll style in css) within each <li>, but before the actual <a ... > element ...
0
votes
2answers
65 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?
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
3answers
114 views

Why isn't my rewrite rule working when there is no second parameter?

Here is my rewrite rule code: add_rewrite_rule('tides/([^/]+)/([^/]*)', 'index.php?page_id=4348&location=$matches[1]&month=$matches[2]', 'top'); add_rewrite_tag('%location%', '([^&]+)'); ...
1
vote
1answer
53 views

Grab Wordpress Salt Data From URL

I'm looking to grab only the values of the Wordpress salt information from this URL with PHP: https://api.wordpress.org/secret-key/1.1/salt I want to target the second set of values within single ...
0
votes
1answer
319 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
216 views

Delete/replace img tags in post content for auto published posts [closed]

In my blog I have set up auto-publish for posts and I get 5 thousands new posts every day, in this moment I have more than 150 thousand posts. I need a script, or a plugin, or a function to connect ...
-2
votes
1answer
215 views

Regex For Extracting First 4 letters of search term

I am using a redirection plugin and want to redirect the existing search url http://www.example.com/search/abcdef to http://www.example.com/?s=abcd I am able to redirect /search/abcdef to /?s=abcdef ...
2
votes
1answer
205 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: ...
1
vote
1answer
132 views

String regex match replace for role 'contributor' only

currently I'm using the below code to add rel=nofollow and target=_blank to all external links of my site's content but I would like this to happen only on Contributors posts. IE, Authors posts and ...
1
vote
1answer
2k views

Wordpress returns 404 on custom rewrite rule conflict in parameters

I have been following the steps on the answer here and it worked wonders. But my problem is on this part, on the original: add_filter('rewrite_rules_array', 'mmp_rewrite_rules'); function ...
1
vote
1answer
269 views

preg_replace and comment_form_defaults

this was kinda of a joke at the beginning but now I'm wondering if it's possible to use regex with the hook comment_form_defaults. Here is what I'm looking for : function remove_default_allowed_tags( ...
1
vote
1answer
155 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 ...
3
votes
1answer
2k views

Change html structure of all img tags in Wordpress

I have a Wordpress blog and am trying to implement the foresight.js image script. In short, I need to target all post images, swap out the src, width, & height attributes with data-src, ...
1
vote
3answers
3k views

Getting attribute value from shortcode

I have this shortcode [learn_more caption="something here:"] [/learn_more] I want to extract the caption value and remove other stuff. "something here:" This is the code that I have, but it ...
-1
votes
2answers
329 views

Get URL from shortcode tag

I am running a wordpress site and I need the correct regex syntax to get a URL from some shortcode that is returned inside the_content(). When I use the_content(), it will return something like ...
0
votes
1answer
156 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 ...
2
votes
3answers
708 views

get attributes/part of the gallery shortcode

I'm trying to grab all image id's that are associated with the [gallery] shortcode that are listed as exclude. For example: if my post has [gallery exclude="1,2,3"] I'd like to get a variable that ...