call shortcode in javascript

Javascript code is running in the user’s browser and not on your server (where your wordpress content resides). You could use ajax to call the function which the shortcode is pointing to. Here is how I handle AJAX calls with WordPress: 1) I use a jQuery ajax function to call the wp-admin/ajax.php jQuery.ajax({ url: yourSiteUrl … Read more

How to display the names of users from a specific group with a shortcode?

Below is my own answer to the question. I will appreciate any constructive comment. add_shortcode( ‘group_members’, ‘group_members_shortcode_handler’ ); function group_members_shortcode_handler ( $atts, $content = null ) { global $wpdb; $querystr = “SELECT * FROM wp_groups_user_group”; $users = $wpdb->get_results($querystr, OBJECT); $output=””; foreach ($users as $user) { if($user->group_id == $atts[‘group_id’]){ $firstName = esc_html(get_user_meta($user->user_id, ‘first_name’, true)); $lastName = … Read more

Get all posts containing a shortcode

WordPress isn’t aware of your shortcode until it’s rendered on the front end. So when WP sees it in the content and replaces it, that’s when it’s aware that your shortcode exists. It also promptly forgets about it afterward, of course. So there’s no built in function to do what you’re asking. The best you … Read more

Make shortcode work with nested double quotes

Either way this seems like a very clunky solution for arbitrary markup in shortcode. If only one of attributes is more bulky and includes markup I would consider making shortcode enclosing: [infobox src=”http://www.google.com” title=”Google”] Some description – see more: <a href=”http://www.google.com”>More here</a> [/infobox] You might be to the point when you’ll need to built custom … Read more

How to add ‘class’ attribute into shortcode [audio]?

WordPress allows least three options to manipulate the code to your needs. Use a global variable that you increment with @Jevuska ‘s answer. global $my_audio_player_count; $my_audio_player_count = 0; add_filter( ‘wp_audio_shortcode_class’, ‘wpse221201_audio_shortcode_class’, 1, 1 ); function wpse221201_audio_shortcode_class( $class ) { global $my_audio_player_count; $class .= ‘ my-audio-player-‘.$my_audio_player_count++; return $class; } Remove the built-in shortcode and add your … Read more

How to embed page content in a blog post

Create a shortcode to embed the content. This will always be synchronized. Sample code from an older project. Just updated. 🙂 GitHub: https://gist.github.com/3380118 · This post in German (auf Deutsch) on my blog. <?php # -*- coding: utf-8 -*- /** * Plugin Name: T5 Embed Post Shortcode * Description: Embed any page, post or custom … Read more

How to get shortcode working from custom meta field

You can do this by using ‘the_content’ filter. That way, WordPress will treat the content as it was came from the editor field and execute all the shortcodes: <?php $meta = get_post_meta($post->ID, ‘intSlider’, true); ?> <div id=”sliderWrap”> <div id=”slider” class=”floatLeft”> <? echo apply_filters(‘the_content’, $meta); ?> </div> </div> Just be careful because it will wrap the … Read more

Allowing for multiple template views on the Gallery Settings page when using the Visual Editor

It appears that the templates live in script form <script type=”text/html” id=”tmpl-my-custom-gallery-setting”> To render the above template would require wp.media.template(‘my-custom-gallery-setting’)(view) Since we’re replacing the template: logic then all we need to do is store a list of template IDs. if (!wp.media.gallery.templates) wp.media.gallery.templates = [‘gallery-settings’]; wp.media.gallery.templates.push(‘my-custom-gallery-setting’); Then loop through all available views wp.media.view.Settings.Gallery = wp.media.view.Settings.Gallery.extend({ template: … Read more

shortcode outputs first before the page content [duplicate]

I guess you’ve echoed the result of shortcode callback function rather than returning them. Please check here: http://codex.wordpress.org/Shortcode_API Shortcodes are written by providing a handler function. Shortcode handlers are broadly similar to WordPress filters: they accept parameters (attributes) and return a result (the shortcode output). you need to return the output that will be added … Read more

using html as shortcode attribute

Pass just the element names and convert them to tags in your shortcode: [irt_top_posts post_type=”showcase” container=”div” number=”10″] In your callback: $return “<$container>$return</$container>”;