shortcode

WooCommerce: Merge 3 custom shortcodes in one

跟風遠走 提交于 2019-12-06 15:45:38
I have three separate woocommerce snippets where each one have one function. I'm trying to combine them together in one script but can't seems to return more than one value. function display_woocommerce_order_count2( $atts, $content = null ) { $args = shortcode_atts( array( 'status' => 'completed', ), $atts ); $statuses = array_map( 'trim', explode( ',', $args['status'] ) ); $order_count = 0; foreach ( $statuses as $status ) { // if we didn't get a wc- prefix, add one if ( 0 !== strpos( $status, 'wc-' ) ) { $status = 'wc-' . $status; } $order_count += wp_count_posts( 'shop_order' )->$status; }

Wordpress shortcode for tag list

*爱你&永不变心* 提交于 2019-12-06 15:40:20
I need to insert tags (of the post) inside post in the exact place. (default: they go after) As I understand the only way is to use shortcode and write its description in functions. I think its an easy one including "print $tags_list", but I haven't managed to write the whole piece of code needed. Can you help me? Or advise another way to solve my problem? PS: Maybe another way is to insert tag code inside post, but wordpress editor doesn't understand You don't really need a shortcode unless the position changes per post. To render tags in your template (you could just move the code): <?php

WooCommerce: Display stock quantity for a given product ID on normal Pages or Posts

a 夏天 提交于 2019-12-06 15:07:59
问题 I am trying to display the product quantity for a given product ID outside WoCommerce pages, in the normal WordPress Pages or Posts. I assume you paste some code into functions.php then have a snippet you put in the post or page. I'm really struggling here and only half-baked answers I've found so far where none of them work for me... How do I echo the stock quantity of a WooCommerce product ID on a normal Wordpress page or post? 回答1: The best way is to make a custom shortcode function, that

Regex pattern for shortcodes in PHP

﹥>﹥吖頭↗ 提交于 2019-12-06 02:56:32
I have a problem with a regex I wrote to match shortcodes in PHP. This is the pattern, where $shortcode is the name of the shortcode: \[$shortcode(.+?)?\](?:(.+?)?\[\/$shortcode\])? Now, this regex behaves pretty much fine with these formats: [shortcode] [shortcode=value] [shortcode key=value] [shortcode=value]Text[/shortcode] [shortcode key1=value1 key2=value2]Text[shortcode] But it seems to have problems with the most common format, [shortcode]Text[/shortcode] which returns as matches the following: Array ( [0] => [shortcode]Text[/shortcode] [1] => ]Text[/shortcode ) As you can see, the

Visual Composer custom shortcode template - custom_markup display user input

不打扰是莪最后的温柔 提交于 2019-12-05 13:14:06
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 fine. But I can not display the user input in the shortcode backend element. <?php add_shortcode('simpletext', 'simpletext_shortcode'); add_action('vc_before_init', 'simpletext_vc'); // Frontend output function simpletext_shortcode($atts, $content = '') { ob_start(); set_query_var('content', $content); get_template_part('components/content',

Create Custom Dropdown Box in Tinymce in Wordpress for Shortcodes

不问归期 提交于 2019-12-05 09:07:01
Does anyone know how to create a custom dropdown box in tinymce for Wordpress? I need it to work with at least wordpress 3.0. I have searched the internet for a tutorial on this and I cannot find one. A link to a website tutorial would be great. Thanks in advance. I know this question was already asked some time ago, but as I stumbled across the same problem, I tought I'd answer this question anyways. Maybe it helps someone else. The comments in the source of the DropDown-Control in tinyMCE turned out to be really helpful. You just need to create a dropdown first, using createDropMenu() , then

Dynamic shortcodes and functions in WordPress

醉酒当歌 提交于 2019-12-05 04:36:06
问题 I am having a bit of an issue with autogenerating shortcodes, based on database entries. I am able to get a normal shortcode working i.e: function route_sc5() { return "<div>Route 5</div>"; } add_shortcode('route 5','route_sc'); and the following shortcode to activate it would be [route 5] This works. But what I need is the shortcode to be produced for each database entry. something like: $routes = $wpdb->get_results( $wpdb->prepare("SELECT * FROM wp_routes") ); foreach($routes as $route) {

Calling WordPress get_template_part from inside a shortcode function renders template first

試著忘記壹切 提交于 2019-12-05 02:37:22
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 shortcode which will output the posts. This way they can simply add the shortcode where they wish the posts to appear. I currently have the logic which retrieve the posts separated in its own file. Currently I include it in a page by simply using the get_template_part() function: get_template_part('donation', 'posts'); I looked into how to create a

Shortcode output adding <br /> after new line

人盡茶涼 提交于 2019-12-05 01:13:19
问题 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 '<style>' . $content . '</style>'; } add_shortcode( 'style', 'add_style' ); In the editor of the page I used it as: [style] .image-main{ border:5px solid lightblue; } [/style] On the rendered page it outputs to: <style> <br /> .image-main{<br /> border:5px solid lightblue;<br /> }<br /> </style> How can I set up

css grid shortcodes and wrap in wordpress

喜欢而已 提交于 2019-12-04 19:18:24
I'm using a 12 column css grid with the classes .grid_1, .grid_2, .grid_3, .... .grid_12 I'd like to create shortcodes in wordpress. This is what I did for e.g. a 2 and 10 column style function grid_2( $atts, $content = null ) { return '<div class="grid_2">' . do_shortcode( $content ) . '</div>'; } add_shortcode('grid_2', 'grid_2'); function grid_10( $atts, $content = null ) { return '<div class="grid_10">' . do_shortcode( $content ) . '</div>'; } add_shortcode('grid_10', 'grid_10'); The problem is that those shortcodes need to be wrapped in a .row class to make it work <div class="row"> <div