Articles of regex

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 for adding data to a feed item, I need to alter the item with a […]

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 and it works also I have used print_r() to test that the function is being called but for some reason the links […]

How to filter url on post submission?

I would like to swap out image URLs upon post submission on both content editor field and a custom field cover_image of a custom post type article. For example, the original content may contain image url such as: <img src=””> I would like to swap it to: <img src=””> And have it stored permanently to […]

Get array of shortcodes within string

I do have an post/page where the shortcode “question” occurs many times. What is the best way to get an array of all the “question” shortcodes with their related parms? [question a=1 b=2 c=3 ] [question b=2 c=3 ] [question a=1 b=2 ] [question]

Adding <div> Automatically To <table> In WordPress Using Filter Referencing?

Does anyone know how I would automatically add <div class=”table-responsive”> before every instance of a <table> on a WordPress site using filter referencing? I would also need to add a </div> to every instance of </table> as well.

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’, $posts[0]->post_content, $matches); if (is_array($matches) && $matches[2] == ‘YOURSHORTCODE’) { //shortcode is being used } This only detects the first shortcode in the post content, though. Is that a bug with get_shortcode_regex(), […]

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 Awesome. In other words: if an administrator uses a theme that has Font Awesome font-awesome.css (or font-awesome.min.css) and he uses 2 plugins that […]

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 \P or \p at offset 7 in /nfs/c11/h03/mnt/206871/domains/ on line 230 data-first_letter=”A”> I can see that the problem is in template_tags.php line 230, which […]

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 options, the different rules required for rewriting are getting out of control. I’m currently running at 80 rewrite rules, with no idea of […]

Stripping URLs & Email from post submissions

I want to prevent users posting in this instance of WordPress from submitting URLs and Emails in posts. I’m trying to do it via Regex but I’m not sure if I’m writing the Regex incorrectly because it doesn’t seem to be stripping any URLs (haven’t written the one for emails yet). Can anyone spot what […]