Get URL from shortcode tag

There’s no need to use regex for this. WordPress has a Shortcode API to do this work for you. That codex page includes one of my favorite codex code snippets: function bartag_func( $atts ) { extract( shortcode_atts( array( ‘foo’ => ‘something’, ‘bar’ => ‘something else’, ), $atts ) ); … Right at the start of … Read more

Grab WordPress Salt Data From URL

That returns PHP code. You can just eval it and then reference the various defines directly. However, that is just a random number generator on the back end. There is no pattern to it. You can just generate your own random values instead of pulling them from WordPress.org and it will work just as well … Read more

Shortcode and whitespace formatting problem

You should give the Attributes Section of the Shortcode API WordPress Codex page a read. Unquoted values also must never contain spaces. Short summary, use quotes – either ” or ‘ – for attribute values with a space in it. Because an attribute name isn’t actually needed I think the »Info« part of your name … Read more

Making extra parameters optional

Two points: Your rule isn’t particularly specific. For numeric matches you should be specific about it and specify a) digits and b) how many digits. Year would be ([0-9]{4}), month/day would be ([0-9]{1,2}). You can’t do it with one rule. Add three separate rules instead. add_rewrite_rule( ‘whats-on/([0-9]{4})/?$’, ‘index.php?page_id=71&event_year=$matches[1]’,’top’); add_rewrite_rule( ‘whats-on/([0-9]{4})/([0-9]{1,2})/?$’, ‘index.php?page_id=71&event_year=$matches[1]&event_month=$matches[2]’,’top’); add_rewrite_rule( ‘whats-on/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$’, ‘index.php?page_id=71&event_year=$matches[1]&event_month=$matches[2]&event_day=$matches[3]’,’top’);

Adding regex filter to feedwordpress

Fixed it with: function fwp_rss_regex ($content) { $content = preg_replace(‘/\<[^\>]*\>/i’,”,$content); return $content; } This solved the problem: 1) Because $content was the item I wanted I wanted to pass through fwp_rss_regex, 2) Because I fixed my preg_replace with /______/i , and 3) I realised $content = $post->post_content(); was either a superfluous (though maybe valid) command, … Read more

Gravity forms – get shortcode attribute from post content

If you only have 1 shortcode in the post content, catch the id with this: <?php $text = get_the_content(); preg_match_all(“\bid=”([0-9]+)\b”, $text, $matches); var_dump($matches[0]); ?> In your example [gravityform description=”true” id=”23″ title=”true”], it would output: 23 However, if you use other shortcodes or simple text, in the same post, with that same structure id=123, you might … Read more