BB-Code-like mechanism by which strings enclosed in square brackets can serve as shorthand for longer and more complicated strings. These strings are processed by callback handlers, usually on page load, which replace the bracket enclosed string with the output from the callback handler.

learn more… | top users | synonyms (2)

27
votes
4answers
4k views

Where to put my code: plugin or functions.php?

Is there an easy to understand scheme to decide what kind of code belongs to a plugin or the theme’s functions.php? There are many cases and many debates about that topic, mostly because there are ...
22
votes
7answers
7k views

Conditionally Loading JavaScript/CSS for Shortcodes

I released a plugin that creates a shortcode and requires a JavaScript file and a CSS file to load on any page that contains that shortcode. I could just make the script/style load on all pages, but ...
13
votes
2answers
17k views

How to add a shortcode button to the TinyMCE editor?

How to make any plugin icon in wordpress post? The code I want to insert in plugin code and will appear in post bar [wp-admin/post.php]. Like this image: Output: If I click the icon it ...
12
votes
5answers
2k views

How to include code only on specific pages?

I'm learning about plugins and shortcodes. I noticed that when I activate my plugin its code gets loaded on all of my pages-- even pages that don't have my shortcode. (I don't mean content vs. admin ...
9
votes
4answers
15k views

How to manually fix the WordPress gallery code using PHP in functions.php?

It's been talked many times that Wordpress outputs some really bad code for the built-in gallery function. This is the core code responsible for the gallery output (in /wp-includes/media.php): ...
6
votes
3answers
299 views

how to show the syntaxis of a shortcode

i want to show the syntaxis in some posts about how to run a shortcode, I mean, something like this [myshortcode] but without running it, is that possible?
6
votes
2answers
20k views

How to customise the output of the WP image gallery shortcode from a plugin?

We're building a plugin that displays posts, and we also want to display the image gallery when it is used in a post. However, we need to limit the number of photos displayed? Is that possible?
6
votes
2answers
283 views

current_shortcode() - detect currently used shortcode

In a plugin class I want to provide simple fields for public data: email, phone number, Twitter etc. The list can be extended. See the plugin Public Contact Data on GitHub for details. To keep the ...
5
votes
2answers
3k views

Check if post/page has gallery?

I'd like to run some code only if a gallery (inserted with the [gallery] shortcode) has been inserted into a post/page. I did the following: gallery_shortcode($post->ID) ? $gallery = 1 : $gallery ...
5
votes
1answer
6k views

How to use other shortcodes inside Contact form 7- forms? [on hold]

I noticed that any shortcode that is not part of the contact form 7 builtin shortcodes dont work. For example: I am trying to use an accordion shortcode between form elements in contact form 7. But ...
5
votes
2answers
364 views

How would I create a plugin for my shortcodes?

All tutorials I have found say to add your shortcodes to functions.php in your theme. I would like to break that away from my theme and put that in a plugin so I can share these shortcodes between my ...
5
votes
1answer
253 views

Optimize shortcode callbacks

I created a plugin to add some shortcodes in my WordPress site. But I'm a PHP newbie, so I believe it may have some errors or ways to optimize it. It's working fine, and apparently there are no ...
5
votes
2answers
721 views

Use AJAX in shortcode

I have the following code to the shortcode to display a random quote. Question: how to make a button display a new random quote? I mean, that would hit the button and show you a new quote (without ...
5
votes
1answer
107 views

Autoembeds don't work with paragraphs

I'm writing the below pieces of code in "Text" mode of the posts editor. Does work: http://www.youtube.com/watch?v=xxxxxxxxxxx Does work: <p>test http://www.youtube.com/watch?v=xxxxxxxxxxx ...
5
votes
2answers
627 views

Create custom [sourcecode] shortcode, the right way?

What I want to do Sharing code in posts on WordPress is quite a pain with all the HTML escaping to take care of. So, I plan to enclose code in posts within a custom shortcode called [sourcecode], as ...
5
votes
1answer
855 views

Using preg_replace to separate gallery from the_content?

In a Wordpress theme, I need to separate a gallery from the rest of the_content. I think one could do that with get_the_content and preg_replace but it's a little beyond my skill level how to actually ...
5
votes
2answers
2k views

Add custom shortcode button to Editor

Before the new version of Wordpress 3.0 came out I was using this jQuery code below to add custom buttons for my own shortcodes to the editor toolbar in the admin panel, it worked great. However with ...
5
votes
3answers
1k views

Is there a way to add another row to the tinyMCE kitchen sink toggle?

The tinyMCE "kitchen sink" toggle button shows/hides a row of buttons. I have successfully added my row of shortcode buttons to the tinyMCE editor, but I was wondering if there was a way to make my ...
5
votes
2answers
5k views

How to add multiple buttons to TinyMCE?

I've followed a tutorial on Nettuts on how to add a custom button to TinyMCE (http://net.tutsplus.com/tutorials/wordpress/wordpress-shortcodes-the-right-way/) It works great and all, but i want to ...
5
votes
1answer
2k views

Styling Shortcodes in Visual Editor

Does anyone know how to style the visual editor so that when specific shortcodes are used they are replaced with an image within the visual editor? I have found that many users screw up the shortcode ...
5
votes
1answer
514 views

Change behavior of “Insert into Post” based on attachment metadata

For a custom plugin I'm working on, I have added a checkbox element to the attachments editor in a manner like the answer provided here: How to add a checkbox element to attachments editor with ...
4
votes
3answers
1k views

Nested Shortcode Detection

If you are familiar with this code <?php $pattern = get_shortcode_regex(); preg_match('/'.$pattern.'/s', $posts[0]->post_content, $matches); if (is_array($matches) && $matches[2] ...
4
votes
1answer
2k views

What does extract( shortcode_atts( array( do?

The codex says shortcode_atts() combines user shortcode attributes with known attributes and fills in defaults when needed. The result will contain every key from the known attributes, merged with ...
4
votes
2answers
394 views

Show shortcode without executing it

I am trying to display code in my WordPress page and it isn't working. Everything I read says that you should be able to just use pre tag with code tag and it would be good but when I try to display a ...
4
votes
2answers
994 views

Split Content and Gallery

Is there a way to split up the post content and the gallery short code. I want to display the gallery outside my normal content no matter how or where it is placed. I can use this to get the shortcode ...
4
votes
2answers
1k views

do_shortcode() within Admin Page

I'm using a few plugins that have shortcodes ... however, instead of creating a public page for the content, I've created some new pages within the admin using add_menu_page and I need to know how to ...
4
votes
2answers
3k views

Why might a plugin's 'do_shortcode' not work in an AJAX request?

tl;dr: Contact Form 7's shortcode doesn't work in an AJAX request when called with do_shortcode functions.php add_action('wp_ajax_ps_get_survey_form', 'ps_get_survey_form'); ...
4
votes
1answer
1k views

Is there a way to parse shortcodes in PHP?

Many plugins don't provide a documented way to access their functions from within PHP (e.g. when building a custom theme), but only shortcodes to insert in posts. Is there a standard way of executing ...
4
votes
1answer
297 views

How to return loop contents

At times, I need to return the output of a loop (usually with WP_Query like in this example) for use in a shortcode or with a filter on the_content. The following code that uses object buffering ...
4
votes
2answers
651 views

Remove wptexturize from a shortcode?

Is there a way to remove wptexturize only for a certain shortcode?
4
votes
2answers
2k views

add_filter and changing output captions of image gallery

I'd like to change only one output of native WP Gallery (in media.php) On Smashing Magazine (link) author advises to change whole gallery_shortcode function. But I wondered if is possible to change ...
4
votes
2answers
2k views

TED talks shortcode not working

I am trying to embed a Ted talk video using the shortcode: [ted id=myid] But it's not working. It shows the text instead of the video. Is there any configuration I need to check to make it work?
4
votes
3answers
515 views

How to embed page content in a blog post

I've built an HTML table that is posted on a page in my site, and I'd like to use that same content inside a blog post (something of an announcement of the table's publication). The table is likely to ...
4
votes
1answer
2k views

Solution to render Shortcodes in Admin Editor

I have asked this question about a year ago and I am hoping there is some type of simple solution which will allow me achieve my objective. So here it goes: I often utilize shortcodes within the ...
4
votes
1answer
844 views

How do I escape a ']' in a short code?

How do I escape a right bracket in a short code? I'm working on a Google Map plugin that has encoded points. Sometimes the polygons have the ] in it, which makes WP think that it's the end of the ...
4
votes
1answer
546 views

explode array within shortcode

This functions at the moment but it only returns the first value from the array. I've been struggling to echo, print, explode, or whatever the multiple custom field values that share the same key ...
4
votes
1answer
1k views

How to paginate wordpress [gallery] shortcode?

I am using wordpress gallery shortcode [gallery] I was wondering if there is anyway to paginate them without using a plugin.
4
votes
1answer
864 views

Update all posts automatically when using post_meta

I recently created a new site using wordpress but I'm a rookie - everything I know is trial and error with no formal training. So please, please, please keep your answers as simple as possible. Thanks ...
3
votes
4answers
4k views

How to check if a shortcode exists?

I'm using do_shortcode function to add shortcode in my template. But i would like to check if that shortcode exists before display them. I mean like this If (shortcode_gallery_exists) { echo ...
3
votes
1answer
1k views

Using wp_editor in shortcode

I am building a plugin for frontend submission. I am using shortcodes API to display the form for content submission, but I am having troubles. The problem is, wp_editor echoe's data, and shortcode ...
3
votes
1answer
709 views

do_shortcode() doesn't do shortcodes ;)

Imagine this basic shortcode in your functions.php file: function div_shortcode( $atts ) { return '<div class="div"></div>'; } add_shortcode('div', 'div_shortcode'); So every [div] ...
3
votes
2answers
956 views

Shortcode to insert <!--nextpage-->

Since wordpress does not have a menu icon (aka "user friendly) way to add the command to a post or page, I'm trying to create a shortcode to do it. However, as logic would have it, its not that ...
3
votes
2answers
83 views

How do I make specific plugin functionality apply to different sites in a network?

I have a site specific plugin that I've written for the main site in my multisite network. Now I realize that the shortcodes that are in the plugin are also useful on the sub-sites, however the ...
3
votes
2answers
4k views

What kind of object type is WP_Query?

I am getting this error when I try to return the post_title value from my WP_Query: **Fatal error:** Cannot use object of type WP_Query as array Here is the code: $query = new WP_Query( array( ...
3
votes
3answers
3k views

Add new “Insert Into Post” button with another function

Problem: Add a hook that automatically adds a short tag to video attachments when inserted from the Media Library (video) tab: Update: This works under the 'Media Library' tab — and doesn't break ...
3
votes
2answers
728 views

Set wmode attribute to transparent for the embed shortcode to make drop-down menu hover over YouTube embed in Internet Explorer

When you hover over my drop-down menu using IE8 or IE9, the menu div will display behind the YouTube embedment. It works fine on all other browsers. Upon research, I found out that many others have ...
3
votes
1answer
178 views

Show content only if member left a comment

Functions Php : add_shortcode( 'membervip', 'memberviparea' ); function memberviparea( $atts, $content = null ) { if( is_user_logged_in() ) return '<p>' . $content . '</p>'; ...
3
votes
1answer
3k views

Remove wpautop from shortcode content / remove whitespace in buffering

I am using the Mailchimp plugin ( http://wordpress.org/extend/plugins/mailchimp/ )and it has a shortcode that uses output buffering to grab it's widget's code and spit it out in the content. however, ...
3
votes
2answers
767 views

How to add stylesheets only to pages with specific shortcode?

I'm running a function on pages where the shortcode [make-me-a-map] is used. It enqueues javascript to the page and makes a map. That part works fine (woot!) but I'm having trouble with adding the ...
3
votes
1answer
444 views

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

Possible Duplicate: current_shortcode() - detect currently used shortcode I'm dynamically generating shortcodes with my plugin like this: foreach ($options['grids'] as $grid) { ...