Questions tagged [shortcode]

A shortcode allows WordPress plugin authors to offer hooks for their functionality into templates in a concise manner. Introduced in version 2.5, the shortcode is a definition of an object which accepts optional properties. Use this tag if you are implementing a shortcode and need help with the underlying functionality.

A shortcode allows WordPress plugin developers to offer hooks for their functionality into templates in a concise manner. Introduced in version 2.5, the shortcode is a definition of an object which accepts optional properties.

Example:

[mygallery src = "photos/"]

can be used to include a custom photo gallery from pictures in the photos directory as compared to

myGallery('photos/');

Use this tag if you are implementing a shortcode and need help with the underlying functionality.

The WordPress Shortcode API offers a quick guide to setting up a simple shortcode handler and explains how this should be handled on the backend.

2207 questions
74
votes
5 answers

How to Use AJAX in a WordPress Shortcode?

I have a code to display a random quote. One person wrote a function to implement all of this. But the update data via AJAX for some reason does not work. When you press the button "New Quote", nothing happens. Maybe someone knows why? What needs to…
23
votes
6 answers

Wordpress using echo vs return in shortcode function

I noticed both echo and return works fine for displaying content from a shortcode function in wordpress. function foobar_shortcode($atts) { echo "Foo Bar"; //this works fine } function foobar_shortcode($atts) { return "Foo Bar"; //so does…
kabirbaidhya
  • 3,264
  • 3
  • 34
  • 59
18
votes
1 answer

Visual Composer custom shortcode template - custom_markup display user input

I have created some shortcode elements. Now I want to customize the look of the elements in the backend editor. From the description of the wiki of VC-Pagebuilder, I get out that I can use the "custom_markup" param for this. For simple html it works…
16
votes
3 answers

how to insert shortcode into wordpress menu

I have made a menu item with this code. The menu item shows up but the shortcode output is not there. Is there something I can add or a different method that will do this. I have added also in hopes this might help. add_filter('wp_nav_items',…
xyz
  • 2,253
  • 10
  • 46
  • 68
15
votes
2 answers

Wordpress: shortcode doesn't work when getting post content using function get_post_field()

I want to get the post content by id outside the loop, so i am using following code: echo get_post_field('post_content', $postid); It works fine, however, if the post contains any shortcodes, the shortcodes don't work properly. It only echoes…
user3396122
  • 153
  • 1
  • 1
  • 5
14
votes
2 answers

render Visual Composer shortcodes onto page

I am trying to echo visual composer shortcodes onto a page. I've tried both methods below, but they don't work: functions.php: Method 1 /* * add shortcode file */ function include_file($atts) { $a = shortcode_atts( array( 'slug' =>…
Jadeye
  • 3,551
  • 4
  • 47
  • 63
14
votes
7 answers

remove empty

tags from wordpress shortcodes via a php functon

Looking for a php function (non-jQuery or wpautop modification) approach to remove

from within wordpress. I tried this but it does not work: function cleanup_shortcode_fix($content) { $array = array ( '

['…

Jason
  • 462
  • 1
  • 9
  • 23
13
votes
6 answers

Wordpress Contact form 7 custom shortcodes

Contact form 7 has some shortcodes, like [_date] to get todays date. But I want to display the date one week from now. So I need to create a custom shortcode to Contact form 7 that takes say [next_week] and in the recived email the correct date is…
halliewuud
  • 2,735
  • 6
  • 30
  • 41
12
votes
4 answers

Calling WordPress get_template_part from inside a shortcode function renders template first

I have a page where I need to allow the user to enter a paragraph of text. Then after that text, insert a shortcode that will render a list of posts, then add more free-form text after that. My thought was that they should be able to insert a…
Gary O. Stenstrom
  • 2,284
  • 9
  • 38
  • 59
10
votes
4 answers

Wordpress shortcodes pass array of values

I am creating some WordPress short codes aimed at providing internal navigation on a page (one page with a lot of content sections and it own menu). This is what I have: //menu function internal_menu($atts) { extract(shortcode_atts(array( …
mcneela86
  • 1,029
  • 3
  • 18
  • 35
9
votes
2 answers

Use WordPress shortcode to add tags

I'm writing a simple WordPress plugin that uses shortcode. I want the page that contains the shortcode to have specific tags. Is this possible? And if so, is there an elegant way to do it? I know that I can add tags with the wp_head…
emersonthis
  • 32,822
  • 59
  • 210
  • 375
9
votes
2 answers

Elementor page builder shortcode issue

I'm facing a weird problem when using the Elementor Wordpress Page Builder. After creating a custom shortcode and inserting it into any page position, it also shows up at the top of the page, but only in Edit mode. Top of the page: Place where I…
Fahem Ahmed
  • 91
  • 2
  • 6
9
votes
5 answers

Custom shortcode in Wordpress Nav Bar

I just want to add a shortcode button to my wordpress theme menu bar for handle the bootstrap modal view function. I tried 'Shortcodes in Menus' plugin, but it doesn't work. I couldn't find alternative plugin for shortcodes in menu so I installed…
emresancaktar
  • 1,507
  • 17
  • 25
9
votes
2 answers

Shortcode output adding
after new line

I'm trying to create a shortcode to add a CSS style attribute to a page. I added the following code to my theme's functions.php. function add_style( $atts, $content = null ) { return ''; } add_shortcode( 'style',…
spencer.sm
  • 19,173
  • 10
  • 77
  • 88
9
votes
2 answers

in woocommerce, is there a shortcode/page to view all orders?

I'm using the plugin woocommerce for my wordpress site, and need a section where member can see their order history. Are there any shortcodes or page in woocommerce that shows the order history of a member?
dave
  • 14,991
  • 26
  • 76
  • 110
1
2 3
99 100