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
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
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
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
35 votes
8 answers
71k views

Stop WordPress automatically adding <br> tags to post content

Is there a way to stop WordPress from automatically inserting <br> tags when adding returns in the WordPress text editor. I would like for it to behave more like a code editor where I can ...
mvaneijgen'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
25 votes
2 answers
97k views

apply_filters('the_content', $content) vs do_shortcode($content)

Lets say I have a theme option or custom postmeta text area. Now I want to execute multiple shortcodes, general texts, images etc. What will be best practice and why? Option 1: $content = //my text ...
тнє Sufi's user avatar
  • 1,710
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
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
6 answers
15k 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 ...
Laxmidi's user avatar
  • 971
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
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
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
19 votes
1 answer
63k views

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

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 ...
alhoseany's user avatar
  • 1,201
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
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
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
16 votes
1 answer
71k views

How to create a shortcode with 1 parameter (atts)

I am having trouble getting a shortcode to work with 1 attribute. Here is my shortcode [sme_user-email userID="2"] Here are my scripts - none of them work. function getUserEmail_func($atts) { ...
tammy's user avatar
  • 541
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
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
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
12 votes
1 answer
3k views

Custom media upload content for inserting custom post shortcode

I’m working on a plugin that creates custom post type “portfolio” along with shortcode to insert in any page or post. The shortcode is: [portfolio option1=“1” option2=“0” option3=“1” ] And it works ...
Nikita's user avatar
  • 419
11 votes
3 answers
46k views

Return HTML Template Page with PHP Function

I want to create a form that I can use a shortcode to insert into my site. It would be really nice if I could create the HTML part in a seperate file and then insert it with a PHP shortcode (to ...
William's user avatar
  • 545
11 votes
3 answers
707 views

how to show the syntax of a shortcode

I want to show the syntax in some posts about how to run a shortcode. I mean, something like this [myshortcode] but without running it, is that possible?
greenbandit's user avatar
11 votes
2 answers
7k views

Custom shortcode being executed when saving page in wp-admin

I'm working on a custom shortcode: [abuzz-store slug="woolworths" fields="description,level,phone" more="true"] The shortcode is working correctly on the website frontend. However, I can no longer ...
Matt Stone's user avatar
11 votes
1 answer
2k views

Add self-closing shortcode button to TinyMCE in WP 4.6

I'm familiar with creating self-closing shortcodes like: // shortcode function wpse_shortcode_example( $wpse_atts ) { // Attributes $wpse_atts = shortcode_atts( array( '...
user9447's user avatar
  • 1,772
11 votes
1 answer
3k views

Change appearance of shortcode text inside editor

Is it possible to change appearance of shortcodes in editor or in whatever way make it more distinguishable from surrounding text? For example if the content of a post is like this... Reference ...
Ivan Topić'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
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
10 votes
4 answers
68k views

Wordpress plugin shortcode not working

I have a shortcode defined in a plugin as follows: // [tag1] -> Some Longer Text function shortcode_example1() { return 'Some Longer Text'; } add_shortcode('tag1', 'shortcode_example1'); Now ...
dhundupothu's user avatar
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
9 votes
2 answers
8k views

Using get_option() in JavaScript

Previously, I used the get_option() function to get an option in PHP, like this: $width = get_option('my_width'); This is inside a shortcode function. Now, I want to have an option in JavaScript. ...
user avatar
9 votes
4 answers
2k views

How to get shortcode's input values inside a filter?

I'm trying to get the input value of a shortcode inside a function that is used by a filter, but there seems to be no success. Here is what i did: function my_shortcode_function($atts){ $value = $...
Johansson's user avatar
  • 15.3k
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
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
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
8 votes
2 answers
13k views

Get current post id witout passing in shortcode

Is that possible to get current post ID without passing in shortcode as parameter. Like [related-post] I want to get the post ID in which post this shortcode will use. add_shortcode( 'related-article'...
Gorakh Shrestha's user avatar
8 votes
3 answers
17k views

Why are you using add_action for shortcode?

I would like to create shortcodes, but some tutorials write about to use add_action: add_action( 'init', 'register_shortcodes'); But I read another tutorial where the author didn't use it, only put ...
Rolnin's user avatar
  • 119
8 votes
2 answers
29k views

How to get URL param to shortcode?

I can't find solution for this ... URL: www.foo.com/some_page/?name=John Page content: Hi [Name]! Worpress still redirects back to www.foo.com/some_page/ I tried everything ... I need ...
Karel Funda's user avatar
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
7 votes
2 answers
4k views

How does a shortcode work?

I know how to use shortcodes, even making them but what I need to understand is that a shortcode is a plain text stored in database as a post content, So how a plain text like this can be converted ...
Mohamed Omar's user avatar
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
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
7 votes
1 answer
4k 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 ...
OriginalEXE's user avatar
7 votes
2 answers
12k views

Encode text string being appended as query to URL [closed]

I have a shortcode in use at present that embeds a button on selected product pages. Upon clicking this button, the user is brought to a contact form on another page and the title of the Product from ...
ConM's user avatar
  • 73
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
1 answer
19k views

Featured image shortcode

Each post currently requires the featured image to be duplicated within the post several times. Is there any way in which I could dynamically call the featured image back into the post rather than ...
Allan's user avatar
  • 71
7 votes
3 answers
38k views

Create a shortcode to display custom post types with a specific taxonomy

I created a page template to list all products of a specific product line. Now I want to list all posts from this custom post type (products) based on the taxonomy described in the shortcode for each ...
Luan's user avatar
  • 183
7 votes
5 answers
26k views

Wordpress removing <p> tags?

I'd already come across a case where Wordpress added <p> tags. However now I'm dealing with the opposite situation. When I add [] shortcodes inside <p> tags WordPress automatically removes ...
Lisandro Vaccaro's user avatar
7 votes
4 answers
14k views

How to display the site name in a WordPress page, or post

I'm trying to create a set of legal pages, that I can add to any WordPress site. Within these pages, I want to mention the site name. Is there a built in shortcode or something, that I can include in ...
Alex's user avatar
  • 71

1
2 3 4 5
56