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.
15
votes
3answers
826 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 ...
14
votes
5answers
4k 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 ...
9
votes
5answers
1k 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 ...
6
votes
3answers
222 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
7k 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):
...
5
votes
2answers
259 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
183 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 ...
4
votes
2answers
12k 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?
4
votes
3answers
936 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
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 : ...
4
votes
2answers
4k 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 ...
4
votes
1answer
177 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
528 views
Remove wptexturize from a shortcode?
Is there a way to remove wptexturize only for a certain shortcode?
4
votes
3answers
248 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
2answers
3k 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 ...
4
votes
1answer
426 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
350 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
1answer
101 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 ...
3
votes
1answer
487 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
324 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 ...
3
votes
1answer
106 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 ...
3
votes
2answers
545 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 ...
3
votes
2answers
76 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
1answer
2k views
How to use other shortcodes inside Contact form 7- forms?
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 ...
3
votes
2answers
115 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
109 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
238 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
1k 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');
...
3
votes
1answer
690 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 ...
3
votes
3answers
2k 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
1answer
237 views
Adding Custom Fields for Img in Posts
I'm wondering how I'd be able to set a custom field within my Wordpress posts. I want to have a field available to add an image via the Post dashboard - that has a max width & max height set, I ...
3
votes
2answers
932 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 ...
3
votes
2answers
553 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 ...
3
votes
1answer
427 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 ...
3
votes
1answer
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 ...
3
votes
4answers
388 views
Run shortcode before filters
My users post snippets code in comments.
I created a shortcode for this :
function post_codigo($atts,$content=""){
return '<code>'.$content.'</code>';
}
...
3
votes
1answer
854 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 ...
3
votes
1answer
1k 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 ...
3
votes
1answer
65 views
How to display the names of users from a specific group with a shortcode?
I have in the database a table with the user_id and corresponding group_id values, so each row contain the ID of the user that is a member of a group and the related group ID. The question is: How to ...
3
votes
5answers
1k views
Cannot strip JW Player shortcode?
On the WordPress archive template I am using a custom excerpt function that includes a reference to strip_shortcodes(). For some reason, shortcodes are being rendered and displayed in the archive.
...
3
votes
1answer
299 views
Using action hooks inside of a shortcode
I am trying to create a modular plugin that includes action hooks for developers to add content before and after the main shortcode content. I'm having some trouble because anything I do in the ...
3
votes
1answer
44 views
When to use which plugin output method?
I'm a Drupal dev, getting into Wordpress. So far as I can tell there are a few different methods by which a plugin can output content on to a Wordpress site:
Shortcode
Rewrite API
Widget API
...
3
votes
1answer
199 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?
3
votes
2answers
203 views
All shortcodes not working on custom theme
I'm using a custom theme not developed by myself that seems to have disabled/ or doesn't have the function for any and all Shortodes, whether its a WordPress shortcode or a plugin shortcode. I mostly ...
3
votes
1answer
365 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 ...
2
votes
3answers
646 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 ...
2
votes
1answer
122 views
Audio tags around Mp3 URL in content
I have an audio player than uses the following syntax to display its player:
[audio src="http://somedomain.com/wp-content/uploads/2013/01/songtitle.mp3"]
The thing is, I'm pretty sure I can show the ...
2
votes
2answers
412 views
Organizing shortcodes. How to display all of them and their attributes?
1. My shortcodes
I've developed multiple shortcodes for my own theme, I'm loading them in functions.php like this require_once (MY_URL . '/bartag_shortcode.php').
Here's an exemplary bartag ...
2
votes
2answers
298 views
shortcode inside another shortcode
I wonder if is it possible to have a shortcode inside another one?
My scenario is this:
I create a shortcodes to display content into columns so I can manage the layout of the page more easily. Now ...
2
votes
2answers
2k 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( ...
