Articles of regex

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.

How do I remove all hyperlinks that begin with a #?

Facebook’s Instant Articles rejects articles that contain hyperlinks to the current page (e.g. <a href=”#_ftn1″>[1]</a>). How can I filter the post content to remove these links before publishing to Facebook Instant Articles? I’m aware of a similar question on StackOverflow: How to remove hyperlink of images in wordpress post?, but my RegEx skills aren’t good […]

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 list view of /lists/games/ (which works just fine) to a single post view of that particular post. My rewrite […]

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 print the shortcode as it is. $exclude_codes = ‘learn_more’; $wp_content = preg_replace(“~(?:\[/?)(?!(?:$exclude_codes))[^/\]]+/?\]~s”, ”, $wp_content); Thanks

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 function, that’s how I’m trying to do: $pattern = get_shortcode_regex(); preg_match(‘/’.$pattern.’/s’, $post->post_content, $matches); if (is_array($matches) && $matches[2] == ‘section’) { $attribureStr = str_replace (” “, “&”, trim ($matches[3])); $attribureStr […]

How to apply content filter permanently?

I have the following temporary filter to fix a content error. We have data in our posts that have 4 digit zip codes, because the leading zero was cut when the original file was created. (For instance, a Massachusetts zip code is 0XXXX, but now in our content it is XXXX) function fix_zip_code($content){ if (preg_match(‘/<span […]

Wrap First Character after </h3><p> in a <span> tag

This is a continuation from a question I asked earlier about doing this with output from the_excerpt(). What I am trying to do is take the following output from the_content() to take the following output as it currently is: <h3>Heading</h3> <p>Paragraph</p> And have it do the following: <h3>Heading</h3> <p><span class=”dropcap”>P</span>aragraph</p> I successfully did this with […]

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 and stuff like that. What I am trying to figure out is what code I need to add to […]

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: http://example.com/%category%/%mycustomfield%/%postname% I can manage to get the %mycustomfield% as %psubject% working by using add_action( ‘init’, ‘register_rewrite_tag’); function register_rewrite_tag() { add_rewrite_tag( ‘%psubject%’, ‘(.*)’ ); […]

Custom Post Type relationship with hierarchical parent and child permalinks

Trying to get my permalink and url structures to behave nicely. I have a Custom Post Type called Diseases. This post type is hierarchical with parent and child relationships. I have another CPT called Content, and I’m using ACF relationships to connect these posts with Diseases. Functionally this all works fine, I can even rewrite […]