displaying content that includes shortcodes within an echo

If some of your comments will contain shortcodes and some won’t, there’s no harm in running them all through do_shortcode(). If the content has no shortcodes in it, it will simply be returned, and if it does contain shortcodes, they’ll be parsed and the content returned. So you should be able to change echo ‘<span>’.$comment_content.'<br>’; … Read more

Shortcode To Display Post Custom Field Value in Post Title, Post Content

the_title filter takes two parameters, one of them is the ID of the post for which it was called. Something like that should work. add_filter( ‘the_title’, ‘se385007_title_filter’, 20, 2 ); function se385007_title_filter( $title, $post_id ) { $new_title = str_replace( “[geo_name]”, “[geo_name post_id=$post_id]”, $title ); return do_shortcode( $new_title ); )

Shortcode to update user meta

Basically, you can’t show the button and update the meta at the same moment. This has to be done in two separate requests as follows: Show the button whereever you want. It needs to be a form that submits to the same page (or an ajax call to another URL, but let’s keep it simple … Read more

Render Modula Plugin Shortcode On Ajax Request

I can only comment on this on a general level as I’m not familiar with the plugin you’re using. (This might also not be the best place to ask this kind of plugin related questions as 3rd party plugins are currently considered off-topic here on WPSE.) Majority of this kind of plugins I’ve encountered have … Read more

Using a custom shortcode from within the template of a shortcode plugin

If I understand it correctly, inside the shortcode template, you could do something like this: echo do_shortcode( ‘[ta-intentclicks-link url=”‘ . esc_url( $list_item[‘link’] ) . ‘”]Visit website[/ta-intentclicks-link]’ ); But then, instead of having to use do_shortcode(), you could actually simply call the shortcode callback from the (shortcode) template ( which then eliminates the need to find … Read more

echo something inside a shortcode

There are a few to do this: Using double quotes Don’t forget to escape the double quotes inside the string. global $post; echo do_shortcode(“[sc name=\”$post->post_name\”]”); Using sigle quotes global $post; echo do_shortcode(“[sc name=”$post->post_name”]”); Using sprintf global $post; echo do_shortcode( sprintf(‘[sc name=”%s”]’, $post->post_name) ); Using wp_sprintf global $post; echo do_shortcode( wp_sprintf(‘[sc name=”%s”]’, $post->post_name) ); Using heredoc … Read more

How to create a shortcode with html and php code

You can use PHPs output buffering, using ob_start to turn on the buffering and ob_get_clean to get and delete the current output buffering. So going by your code it would look like this function blogPost(){ ob_start(); ?> <section class=”blog container spacer”> <article class=”blog__list”> <div class=”glide-blog”> <div class=”glide__arrows” data-glide-el=”controls”> <button class=”glide__arrow glide__arrow–left” data-glide-dir=”<“>&lt;</button> <button class=”glide__arrow glide__arrow–right” … Read more

Returning data instead of echoing/printing

The problem with your code, as you mentioned, is that you are outputting the images via your print_r function, and you need to instead build a string to return, which is displayed in place of the shortcode. Give this a try: function get_media () { $attachments = get_posts([ ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, ‘post_status’ … Read more

Use html inside shortcode function

There are several things you need to know, after which the problems become obvious: you join strings together using . for example ‘hello’ . ‘world’ is the same as ‘helloworld’ You end a statement/action/call with ;, this is you telling PHP that you have finished saying something, and you are going to say something new … Read more

Anyway to convert a plugin to become a shortcode?

Sure, but it will take a little bit of hacking. I took a quick look at the plugin and what you want is in the function rax_social_media_share_show_option(). I would copy it and make a new function with just the part that builds up $button_code. That’s from line 315 to 516. Add a simple one-tag shortcode … Read more