How to use get_media_embedded_in_content function

The get_media_embedded_in_content() function is a handy helper function, though it doesn’t seem to be used in the core (ver. 4.2.2). Regular expression: To understand the get_media_embedded_in_content() function, we must understand the following regular expression: #<(?P<tag>video|audio|object|embed|iframe)[^<]*?(?:>[\s\S]*?<\/(?P=tag)>|\s*\/>)# There are many online regular-expression tools to help us with that. Like this one: Debuggex demo We note that it’s … Read more

WordPress Shortcode and Dynamic CSS

The closest to a reference technique in core would be shortcode. If you look at the source of implementing gallery_shortcode() function you’ll see that it: Generates instance number (so multiple shortcodes can be distinguished). Outputs dynamic CSS inline into a page source, for each instance. I wouldn’t consider it particularly neat solution, but it is … Read more

Search content for shortcodes and get parameters

This is working for me $shortcode=”book”; $pattern = get_shortcode_regex(); // if shortcode ‘book’ exists if ( preg_match_all( “https://wordpress.stackexchange.com/”. $pattern .’/s’, $post->post_content, $matches ) && array_key_exists( 2, $matches ) && in_array( $shortcode, $matches[2] ) ) { $shortcode_atts = array_keys($matches[2], $shortcode); // if shortcode has attributes if (!empty($shortcode_atts)) { foreach($shortcode_atts as $att) { preg_match(‘/id=”(\d+)”https://wordpress.stackexchange.com/”, $matches[3][$att], $book_id); // … Read more

Video embeds work in backend, but are not parsed in frontend

I’ve just looked at the source of the WP_Embed class, and it appears they are not actually registering a shortcode, but hooking into the the_content filter. Change your code to $content_desktop = apply_filters(“the_content”, get_the_content()); or manually trigger their filter with something like $content_desktop = WP_Embed::run_shortcode(get_the_content()); or, if you prefer to have an object: $myembeds = … Read more

Need MySQL Query or WP-CLI command to updates old URLs in Shortcodes [closed]

You should try running WP-CLI’s search-replace command. $ wp search-replace ‘http://example.com’ ‘https://example.com’ –all-tables But you said these URLs are placed from a shortcode? Then you need to find out what this shortcode actually is doing. As it not necessarily has saved the URLs to the database. Maybe it’s a setting in the shortcode and then … Read more

How to call shortcode function directly and pass $atts

do_shortcode() just parses the string. You have to use echo or print to print it out. function_exists() expects a string that matches a function name. After looking at the plugin, I would try this code: <?php if ( function_exists( ‘mediacategories_func’ ) ) { ?> <h1>Inspiration</h1> <?php print mediacategories_func( array( ‘categories’ => 6 ) ); }

Shortcodes, HTML tables, and multiple rows

pass your data in single variables delimited by some char: [myproduct cols=”name,quantity,price” data=”name1,5,2.00,name2,3,3.25″] then explode it into an array and output. I didn’t bother with table markup here, but you get the idea: function myproduct_func( $atts ) { extract( shortcode_atts( array( ‘cols’ => ‘none’, ‘data’ => ‘none’, ), $atts ) ); $cols = explode(‘,’,$cols); $data … Read more

Adding Custom Fields for Img in Posts

You should use the post thumbnail feature. Add support for this feature with this line in your functions.php file: add_theme_support( ‘post-thumbnails’ ); You can also set a new thumbnail size that will be cropped on new added photos to use this in your theme. Add this code to set a new thumbnail size (also in … Read more