Get shortcode attribute outside of WordPress

Don’t try to parse the shortcodes and then regex the HTML. Use get_shortcode_regex() to parse the raw post content: $content = $content_post->post_content; preg_match_all(“/$pattern/”,$content,$matches); Then crawl $matches to find your shortcode data. Use shortcode_parse_atts($matches[3][0]) (note $matches[3][0] to give the first element within the matched shortcode’s attributes) to pull apart the attribute string. Reference: https://wordpress.stackexchange.com/a/73461/21376

shortcode get thumbnail size

I think your code is very close, try to use wp_get_attachment_image_src() instead: function thumb_medium( $atts, $content = null ) { // return wp_get_attachment_url( get_post_thumbnail_id( $post_id, ‘medium’) ); global $post; $thumb_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘medium’ )[0]; if ($thumb_url) { return $thumb_url; } } add_shortcode(“get_urlthumb”, “thumb_medium”);

Combining similar shortcode functions?

I don’t know exactly what you are trying to do but perhaps something like this: function customfields_shortcode( $atts ) { if (!empty($atts[‘field’]) && get_post_meta( get_the_ID(), $atts[‘field’], true ) ) { $customfield = get_post_meta( get_the_ID(), $atts[‘field’], true ); return “custom field >> $customfield << custom field”; } } add_shortcode( ‘mycustomfields’, ‘customfields_shortcode’ ); echo do_shortcode(‘[mycustomfields field=”customfield_1″]’); One … Read more

Can a shortcode return its own name?

A shortcode can access its own name – it is supplied as third parameter to the shortcode’s callback function, just like that: function test_shortcode_callback( $atts = array(), $content = null, $tag ) { return $tag; } add_shortcode( ‘test_shortcode’, ‘test_shortcode_callback’ ); // So running this shortcode [test_shortcode] // Will return this test_shortcode

Replace / Remove Shortcode after 1st run / post

You don’t need a shortcode in a traditional sense. You could use something like {imageurl=””http://google.de/aImage.jpg} You would use the filter content_save_pre to run before the content is saved to the database a search and replace with the img markup which you get from media_sideload_image(). media_sideload_image() downloads the image from a URL adds it to the … Read more

Creating multiple enclosing shortcodes and fixing JS issues on click

Code:- function more_shortcode( $atts , $content = null ){ return ‘<div id=”more-outer-‘.$atts[‘id’].'”><a href=”#” id=”more-link-‘.$atts[‘id’].'”>More</a><div id=”more-inner”>’. $content .'</div></div>’; } add_shortcode( ‘more’, ‘more_shortcode’ ); Usage:- [more id=’1′]This is one.[/more] [more id=’2′]This is two.[/more] [more id=’3′]This is three.[/more] Output:- <div id=”more-outer-1″><a href=”#” id=”more-link-1″>More</a><div id=”more-inner”>This is one.</div></div> <div id=”more-outer-2″><a href=”#” id=”more-link-2″>More</a><div id=”more-inner”>This is two.</div></div> <div id=”more-outer-3″><a href=”#” id=”more-link-3″>More</a><div id=”more-inner”>This … Read more

PHP code inside shortcodes

You can not put PHP functions inside your shortcode. However, you do not need to. You can just use your foreach-loop to create the html and store it in a variable, for example $shortcodehtml. So, afterwards, you can call echo do_shortcode(‘[O_U user_name=”operator” blocked_message=”This page is restricted for guests.”]’ . $shortcodehtml . ‘[/O_U]’); The better version … Read more

WordPress shortcode display as plain text

First of all as far as I know that you can’t call get_template_part() from your plugin.It’s a Theme only function . Try to keep your calculator code’s in a php file inside your plugin’s directory and include it like bellow: function info_box_calculator_core(){ include( plugin_dir_path( __FILE__ ) . ‘mydir/calculator.php’); //replace ‘mydir/calculator.php’ with your file name } … Read more

UberMenu list current user’s posts as menu items

the_permalink(), the_title() by default echo their value. As you want to store that value in a variable you will need to return the values instead. get_the_permalink(), get_the_title() are two similar functions that return the value instead of echo. So you new code may look something like this: $list=”<li class=”ubermenu-submenu ubermenu-submenu-id-122-col-0 ubermenu-submenu-type-stack”>”; $list .= ‘<a class=”ubermenu-target … Read more