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

1
vote
1answer
36 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
30 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
171 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
20 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
59 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
0answers
35 views

Customizing Walker_Nav_Menu - Trunicating spaces

I've just started learning to code WP themes pretty much from scratch and I'm trying to figure out how to pass a variable thru a customized Walker_Nav_Menu but without any ascii spaces. The goal is ...
0
votes
1answer
34 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
30 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
27 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
45 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
40 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
110 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
0answers
42 views

Rewrite rule for custom parameter

I'm stuck with rewrite rules regex. I have this kind of link: http://www.xyz.com/page-1_b/page-3_d/page-0_a/box-page-3_d I need to add rewrite rule for this link so that it extracts what's after ...
0
votes
1answer
121 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 ...
0
votes
1answer
189 views

How to Create a Mod_Rewrite/Regex Rule to Redirect Requests old URLs to Their Updated Link Structure

Here goes... How would I create a mod_rewrite rule to that will redirect a variety of possible URL requests to their updated URL counter parts. We are migrating and old site to a CMS with a ...
-2
votes
1answer
31 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
88 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: ...
0
votes
0answers
115 views

Problem with my add_rewrite_rule

I have a rewrite rule that needs to allow me to add 1-3 variables to the end of a page, the variables are then accessed by a plugin using a shortcode. This is the base page: ...
1
vote
1answer
72 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 ...
0
votes
0answers
47 views

how to prevent words inside image tags from being update in a sql query via php

I need to update certain words inside wp_posts table (1032 posts in a specific time range) but I would like to exclude some words when they are inside tags like so: <img ...
1
vote
1answer
566 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
191 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
125 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
1k 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
887 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
173 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
106 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
371 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 ...
1
vote
0answers
70 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 ...
0
votes
1answer
90 views

Photos automatically uploaded to Media Library

Here's a bizarre one for you guys. I was using Search RegEx to remove Blogger html formatting that was screwing up my imported posts. Images hadn't been imported, so they were loading from Blogger ...
2
votes
1answer
478 views

Replacing with(out) regex link to attachment by links to files

I tried to do it myself but I have really hard time with Regex (regex is hell. I just don"t understand). Anyway, I think this would be usefull to some people. The context is that we use a plugin to ...
1
vote
0answers
97 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
143 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) ...
0
votes
1answer
686 views

post->post_content filter

I'm trying to determine if the REGEX I'm using is incorrect -- or if I'm missing something basic here. The following: add_filter('the_content','wpdu_image_replace'); function ...
3
votes
1answer
1k views

Check user logged in with JS

I use FaceBook JS SDK to check whether the user has permission to log in to my site or not. If user has permission I log him into the WP site. It is possible to check with JS whether the user ...
2
votes
2answers
348 views

sql query to put quotes around numbers in img tag

I have quite a few old posts that contain an img tag with height and width with no double quotes around the numbers. For example: <img height=319 alt="" ...
2
votes
4answers
950 views

rewrite rules and querystring

When I go to the url mysite.com/photos/120 I'm wanting to get the 120 out. In the PHP I want to be able to grab these "parameters" like the url was mysite.com?page=photos&id=120 or even just ...
-1
votes
1answer
839 views

Strip Twitter Username from Profile Field with URL and Save to New Profile Field

Let me start by saying, I am not a coder, but enjoy learning. Here is the situation. I have many custom profile fields for social media added to my user profiles. The user enters the full URL of ...
1
vote
3answers
372 views

Making extra parameters optional

I've setup a very specific function and it works well but I'd like to make the parameters optional but I can't get a handle on the regex bit: add_rewrite_rule('whats-on/([^/]+)/([^/]+)/([^/]+)/?$', ...
2
votes
1answer
117 views

Rewrite of URL with '[' ']' or '(' ')' as literals

Trying to match and URL like this linktosite/alphaNum/123/321/alphanum[alphanum].jpg in .htaccess I can match and extract all the groups properly with ...
0
votes
2answers
2k views

How to make search include data from wp_postmeta?

I have a site using Advanced Custom Fields to create and store various bits of relevant info. These need to be included in the main general search, which by default only searches the title and main ...
1
vote
1answer
910 views

extract shortcodes from string

i need a little help to with this issue: I have a string wich contains shortcodes like [shortcode data="1" data2="2"] How I can extract with regex? without wordpress system? Thanks in advance.
0
votes
2answers
204 views

How to deal with Wordpress bug: can't use wrapped and unwrapped shortcode on same post

After trouble parsing wrapping and non-wrapping shortcodes on the same page, I came across this trac ticket from 3 years ago: http://core.trac.wordpress.org/ticket/9264 The trouble is WP cannot ...
0
votes
2answers
242 views

Dynamically append custom post type to end of url

At the moment my nav menu's category list only links to normal post_type archives. I'd like to dynamically append a custom post type, specifically ?post_type=portfolio, to the end of each url that ...
-1
votes
1answer
104 views

Test for IP in Array Always Fails on First IP

I'm working on a IP restriction plugin but having a strange problem. I have a textarea in the settings page where each of the IP addresses that should be allowed are entered, one per line. I'm then ...
1
vote
1answer
174 views

Regex to Remove File Extension

I am using the Redirection plugin and I would like to use it to redirect my old static html pages to the new Wordpress pages. So basically anything that looks like http://www.example.com/page.html ...
0
votes
1answer
173 views

Extract Information from post content (using regex?)

I'm trying to replace some custom strings in my content before saving the post. I have got the $data["post_content"] which includes strings like %replaceContent:{type}% . Now I need to extract that ...
0
votes
2answers
341 views

how to properly rewrite url by custom var

ive been trying to rewrite a shop uri, and what i have now is this code: add_filter('rewrite_rules_array','wp_insertMyRewriteRules'); add_filter('query_vars','wp_insertMyRewriteQueryVars'); ...
0
votes
1answer
615 views

get_shortcode_regex() only matches first shortcode

The Codex has an example of using get_shortcode_regex() to check if a shortcode is being called on a given page: $pattern = get_shortcode_regex(); preg_match('/'.$pattern.'/s', ...
-1
votes
2answers
1k views

How to strip/remove all blank spaces at the beginning/end of a search string

I use hack of Chris_O for highlighting the search terms. When a user enters the search keywords without any blank space in the beginning or at end of the search string it retrieves and highlights the ...