Skip to main content

Questions tagged [shortcode]

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.

Filter by
Sorted by
Tagged with
99 votes
7 answers
18k 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 ...
fuxia's user avatar
  • 107k
7 votes
4 answers
3k views

Shortcode outputs at the top of the_content

The shortcode produced by this function - a list of all sites in a multisite - outputs above the content in the loop, no matter where it is placed in the editor. I've looked at the other related ...
markratledge's user avatar
  • 8,735
86 votes
10 answers
68k views

Enqueue Scripts / Styles when shortcode is present

What is the idea way to register/enqueue scripts and/or styles for use in plugins? I recently made a plugin simple plugin to add the user avatar/gravatar with a shortcode. I have different style ...
Bryan Willis's user avatar
  • 4,429
20 votes
2 answers
24k views

Shortcode always displaying at the top of the page

I'm using a shortcode to pull in different loops via the loops-name.php. For some reason it is always at the top of the page. I googled it and using echo instead of return causes that problem but with ...
john joe's user avatar
  • 205
5 votes
3 answers
2k views

short code output too early

I'm trying to create a shortcode base on the following code: <ul class="filter"> <li>Filter:</li> <li class="link-store"><a href="<?php echo get_permalink( 23 ); ?>"&...
andresmijares's user avatar
15 votes
4 answers
19k views

Redirect function inside a Shortcode

I am developing a free plugin for connection a external support system to WordPress to be able to authenticate users on WordPress. For this, currently from the external system, the user is sent to ...
Harish Chouhan's user avatar
35 votes
1 answer
47k 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 ...
user avatar
17 votes
2 answers
44k 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?
jnthnclrk's user avatar
  • 1,825
41 votes
7 answers
18k 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 ...
Ian Dunn's user avatar
  • 4,837
9 votes
2 answers
7k 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 ...
user23769's user avatar
20 votes
5 answers
7k 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 ...
Jamie's user avatar
  • 1,363
15 votes
2 answers
13k 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 ...
dcolumbus's user avatar
  • 637
9 votes
2 answers
19k 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'); add_action('...
djb's user avatar
  • 2,250
23 votes
3 answers
15k 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 ...
Howdy_McGee's user avatar
  • 20.7k
17 votes
4 answers
30k 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): ...
its_me's user avatar
  • 4,502
3 votes
3 answers
9k views

How to make shortcode to hide selection of text from post or page?

is there any shortcode or a plugin that will add new quicktag, like this example: [hidemytext]some hidden text[/hidemytext] and any text inside those tag is hidden from the post or from the page. ...
user25236's user avatar
11 votes
2 answers
2k 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 ...
fuxia's user avatar
  • 107k
5 votes
1 answer
1k 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 ...
mrwweb's user avatar
  • 10.3k
-1 votes
2 answers
8k views

How can I make all gallery images to open in a new window?

How can I make all gallery images to open the high resolution image in a new window?
Mario's user avatar
  • 139
6 votes
1 answer
2k 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 ...
Josh M's user avatar
  • 342
5 votes
2 answers
8k 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 ...
cachaito's user avatar
  • 165
2 votes
3 answers
4k views

WordPress gallery 'post_gallery' filter doesn't work with feeds?

We can use the post_gallery filter to modify/replace the default WordPress gallery template (AKA output code) to suit our needs. But this doesn't seem to affect the markup in RSS feeds. No matter ...
its_me's user avatar
  • 4,502
39 votes
2 answers
66k 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 automatically ...
Juan Lie's user avatar
  • 653
22 votes
3 answers
12k views

Pass boolean value in shortcode

In WordPress shortcodes, how can I pass boolean attributes? Both of [shortcode boolean_attribute="true"] or [shortcode boolean_attribute=true] are giving string values. EDIT There would be no ...
Sodbileg Gansukh's user avatar
22 votes
3 answers
19k 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 ...
NetConstructor.com's user avatar
16 votes
3 answers
20k views

PHP error with shortcode handler from a class

Currently i am using the following generic flow for adding the shortcode for a plugin. class MyPlugin { private $myvar; function baztag_func() { print $this->myvar; ...
xmaestro's user avatar
  • 265
15 votes
6 answers
5k 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 ...
Laxmidi's user avatar
  • 971
7 votes
4 answers
18k views

the_excerpt and shortcodes

I'm using the_excerpt on my index page. I'm also using a dropcap shortcode at the beginning of each of my posts. On the index page, the posts will not display the letter with the dropcap shortcode ...
Colton Allen's user avatar
4 votes
1 answer
27k views

How execute shortcode with javascript

Suppose to have this shortcode: [spu-close class="" text="" align=""] I want to show this short code when I click on a button this is my html: <input class="button b" onclick="openFile(link);" ...
Doppy's user avatar
  • 41
3 votes
1 answer
597 views

How do i link gallery thumbnails to different url's using the wp native gallery?

Is it possible to link each gallery thumbnail if i use the built in WordPress native gallery?
user avatar
2 votes
2 answers
6k views

Counting number of posts in a category and its sub categories and displaying result using shortcode

I am trying to create a shortcode to display the posts count in a category. I have successfully done this using this code: // Add Shortcode to show posts count inside a category function ...
Atef Wagih's user avatar
2 votes
1 answer
2k views

Getting the count of a shortcode that is nested

Let's say I have nested shortcode where the outmost shortcode is just HTML but the inner one is the one who displays the data. [outer_shortcode][inner_code url="#" title="Hello"][/outer_shortcode] ...
Marco Berrocal's user avatar
1 vote
2 answers
3k views

The result of a shortcode appear BEFORE page content

I have a page, with a shortcode that get all the post from a categorie and put after the content of the page. For no apparent reason, the result of a WP_Query() in the shortcode APPEAR ALWAYS at the ...
menardmam's user avatar
  • 882
1 vote
2 answers
6k views

Shortcode display outside the div

I have created a shortcode that retrives and displays a form.The content of the attribute in HTML. function check_my_login( $atts) { return '<form action="" name="" method="post" ...
Pavnish Yadav's user avatar
0 votes
1 answer
3k views

How get a shortcode working in category description

I want to use a shortcode for a table in a category description. It's my understanding that WP does not support this. I searched google and found some codes that i needed to add to the functions.php. ...
Harm Zeven's user avatar
0 votes
2 answers
399 views

How do I create shortcodes for my wordpress themes?

I have seen many professional wordpress themes for sale that have shortcodes built in with which you could easily make posts like this: [alert_box]This is an alert box which based on this short-code ...
Logan's user avatar
  • 13
10 votes
1 answer
14k views

shortcodes output before content [duplicate]

Possible Duplicate: problem with short code Shortcodes are broken. For those of you playing at home, heres an easy step by step to replicate my problem. 1) Open a fresh Wordpress install (3.4.2)...
Neros's user avatar
  • 203
10 votes
5 answers
22k views

Filter specific shortcode output?

Is there a hook in WordPress that I can use to filter the output of a specific shortcode? Something like this: add_filter('shortcode_output', 'my_filter_function', 2); function my_filter_function ( $...
ragulka's user avatar
  • 614
9 votes
8 answers
14k 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 ...
Padraic's user avatar
  • 93
7 votes
1 answer
607 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 ...
drabello's user avatar
  • 403
7 votes
6 answers
10k views

Shortcode empty attribute

Is there a way of creating an empty attribute for a shortcode? Example: function paragraph_shortcode( $atts, $content = null ) { return '<p class="super-p">' . do_shortcode($content) . '&...
Wordpressor's user avatar
  • 5,041
6 votes
1 answer
22k views

Combining shortcode and get_template_part

I manage a wordpress site and have created a template part that I usually paste below the content. <div class="posts-group"> <h2>Featured store products</h2> &...
vlovsky's user avatar
  • 183
6 votes
3 answers
12k views

Remove wpautop from shortcode content / remove whitespace in buffering

I am using the Mailchimp plugin, and it has a shortcode that uses output buffering to grab its widget's code and spit it out in the content. However, the widget code has plenty of white space, so ...
helgatheviking's user avatar
6 votes
1 answer
12k 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.
Ruriko's user avatar
  • 543
6 votes
3 answers
9k 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 =...
csm232s's user avatar
  • 159
5 votes
2 answers
3k views

What characters are allowed as a shortcode tag and how should they be sanitized?

I am working on a plugin where the user can define shortcode tags himself. What would you suggest to allow in there? My thought is only allow ascii characters. So how do I sanitize? strip_tags and ...
amy's user avatar
  • 385
4 votes
2 answers
10k views

enqueue script only if it is not already enqueue

I want to include a script in a shortcode output, so I am trying this: function my_shortcode( $atts, $content = null ) { extract(shortcode_atts(array( 'title' => '', ), ...
enam's user avatar
  • 107
4 votes
1 answer
5k views

Extract attribute values from every shortcode in post

I have multiple shortcodes in the post: [section title="first"] [section title="second"] [section title="third"] I want to extract all title values (i.e first, second, third) from external function, ...
Lionheart's user avatar
3 votes
1 answer
2k views

Shortcodes, HTML tables, and multiple rows

Im trying to build a shortcode which calls an HTML table with a fixed number of columns and a variable number of rows depending on the context. Its hard to manage — or even build, multiple ...
VicePrez's user avatar
  • 678
3 votes
2 answers
4k views

How to call shortcode function directly and pass $atts

I am using the Media Library Categories plugin. It does not have much documentation, so I have concluded the way to implement it would be using the shortcode [mediacategories categories="6"]. I want ...
Evan Yeung's user avatar
  • 3,502

1
2 3 4 5