Get shortcode name from within it’s callback function? [duplicate]

The shortcode’s name is referred to as the tag. The tag is actually the 3rd (and last) parameter passed to the shortcode’s callback function. So your callback should look something like this: function print_shortcode($atts, $content, $tag) { // $atts – array of attributes passed from shortcode // $content – content between shortcodes that have enclosing … Read more

How to add multiple buttons to TinyMCE?

First add your additional buttons inside the buttons callback.. function register_button($buttons) { array_push($buttons, “quote”,”wpse-rules”); return $buttons; } Then add additional buttons function inside the plugin javascript.. init : function(ed, url) { ed.addButton(‘quote’, { title : ‘Add a Quote’, image : url+’/image.png’, onclick : function() { ed.selection.setContent(‘[quote]’ + ed.selection.getContent() + ‘[/quote]’); } }); ed.addButton(‘wpse-rules’, { title … Read more

How to get URL param to shortcode?

If I understand your question correctly, you want to be able to get the parameter from the url, add it to the shortcode so you can add the parameter to the content. See if this works: add_shortcode(‘name’, ‘get_name’); function get_name() { return $_GET[‘name’]; } In the wordpress backend editor you would have something like: Hello … Read more

Why are you using add_action for shortcode?

If you take a look at the Codex page about add_shortcode() you won’t see anything about the need of an add_action() before you can use add_shortcode(). So, you can just put your add_shortcode() directly into your functions.php. This is what I do too. See this article – WordPress Shortcodes: A Complete Guide about the use … Read more

Get current post id witout passing in shortcode

add_shortcode( ‘related-article’, ‘related_article_title’ ); function related_article_title( $atts ) { global $post; echo $post->ID; // currently viewing post id ob_start(); $query = new WP_Query( array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 1, ‘order’ => ‘DESC’, ) ); if ( $query->have_posts() ) { ?> <div class=”menu-row”> <?php while ( $query->have_posts() ) : $query->the_post(); ?> Leggi anche: <a href=”https://wordpress.stackexchange.com/questions/210518/<?php … Read more

Using wp_editor in shortcode

If a function echos data, you can use php output buffering to capture the echoed output and return it instead // Turn on the output buffer ob_start(); // Echo the editor to the buffer wp_editor(); // Store the contents of the buffer in a variable $editor_contents = ob_get_clean(); // Return the content you want to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)