Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
Match string in shortcode using regex

I have this shortcode in my page content in Wordpress. I need to get the value of "layout" and the value from "slug"

So I need the values: listing & aircraft extracted from the string

I am looking for the lowest possible hit to performance. I am trying to get these values from the save_post hook so I don't have access to the normal shortcode $atts parameter.

'[vc_row][vc_column width="2/3"]

[cpt_categories layout="listing" view="grid" items_per_row="4" orderby="title" order="ASC" slug="aircraft"]

[/vc_column][vc_column width="1/3"][/vc_column][/vc_row]'

When using the native WP function shortcode_parse_atts I get close but there are some issues:

$atts = shortcode_parse_atts($post->post_content);
var_dump($atts);
array 
  0 =>  '[vc_row][vc_column' 
  1 =>  'width="2/3"][cpt_categories' 
  'layout' =>  'listing' 
  'view'   =>  'grid' 
  'items_per_row' =>  '4' 
  'orderby' =>  'title' 
  'order' =>  'ASC' 
  2 =>  'slug="aircraft"][/vc_column][vc_column' 
  3 =>  'width="1/3"][/vc_column][/vc_row]' 
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If those two values are literally all you need, then Regex could be a reasonable solution here. (just be careful about the whole "hammer and nails" thing with Regex and HTML)

Match group 1 in layout="([^"]*)" will get you the listing value.

Match group 1 in slug="([^"]*)" will get you the aircraft value.

They both work on your example string (as tested at https://regex101.com/).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!