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

.htaccess restrict subdomain by IP - Wordpress Multisite

I'd like to redirect traffic away from a subdomain install of Wordpress Multisite unless it's coming from a specific IP address/range, and without affecting the root domain traffic. Is this possible? ...
-1
votes
0answers
9 views

How to redirect /%postname%-%post_id%/ to /%postname%/

I expected WordPress to handle this permalink change automatically but it is not doing so. I tried Redirection plugin but it requires Regex. Can anyone suggest what can be added to .htaccess file to ...
0
votes
0answers
22 views

Add custom dynamic string to permalink structure wordpress

I am adding dynamic string to permalink but the problem is all the pages which runs from page.php goes to 404 whereas the detail page of the post is working fine. Code: add_filter('post_link', ...
0
votes
1answer
72 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
47 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
84 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
59 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
206 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
39 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 ...
4
votes
3answers
1k views

Nested Shortcode Detection

If you are familiar with this code <?php $pattern = get_shortcode_regex(); preg_match('/'.$pattern.'/s', $posts[0]->post_content, $matches); if (is_array($matches) && $matches[2] ...
2
votes
1answer
86 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
69 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
110 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
41 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
37 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
62 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
46 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
154 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
45 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 ...
1
vote
1answer
850 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 ...
2
votes
1answer
119 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
1answer
147 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
33 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 ...
1
vote
1answer
89 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
2answers
1k views

How to change the admin menu “Pages” to something else

When one creates a custom post type you have the ability to define various elements related to that post type which essentially allow you to define things such as the menu title, "add new post" text ...
0
votes
0answers
49 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 ...
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
1answer
213 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
135 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 ...
2
votes
1answer
562 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
votes
2answers
208 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 ...
1
vote
3answers
1k 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 ...
2
votes
3answers
471 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 ...
0
votes
1answer
123 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 ...
1
vote
3answers
459 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
122 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 ...
1
vote
0answers
76 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
103 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 ...
1
vote
0answers
101 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
157 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) ...
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 ...
0
votes
1answer
762 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 ...
2
votes
4answers
1k 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
1k 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 ...
2
votes
2answers
380 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="" ...
0
votes
2answers
3k 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 ...
0
votes
2answers
218 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 ...
1
vote
1answer
1k 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
259 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
111 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 ...