shortcode

Calling WordPress get_template_part from inside a shortcode function renders template first

强颜欢笑 提交于 2019-12-22 03:56:09
问题 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

remove empty <p> tags from wordpress shortcodes via a php functon

 ̄綄美尐妖づ 提交于 2019-12-21 03:49:38
问题 Looking for a php function (non-jQuery or wpautop modification) approach to remove <p></p> from within wordpress. I tried this but it does not work: function cleanup_shortcode_fix($content) { $array = array ( '<p>[' => '[', ']</p>' => ']', ']<br />' => ']', ']<br>' => ']' ); $content = strtr($content, $array); return $content; } add_filter('the_content', 'cleanup_shortcode_fix'); 回答1: Try inserting this code in your functions.php file: remove_filter( 'the_content', 'wpautop' ); add_filter(

Adding 'sort by' drop down on custom page using woocommerce short code

谁都会走 提交于 2019-12-20 04:18:26
问题 I have created a custom page using woocommerce short code for product categories. At the moment, it's pretty sparse as I've only just started on the new site. I just need the default 'sort by' drop down element adding but have no idea how to do it. I found some code here >>Woocommerce, sort dropdown on shortcode based product lists and it certainly placed the drop down I need on the site (although I'd like it aligned left). The only problem now, is that it's displaying the products with

Assign Wordpress Short code to PHP Variable?

有些话、适合烂在心里 提交于 2019-12-14 03:18:36
问题 I'm trying to compare a email address held in a PHP variable with a email address held in a short code in Wordpress, this is what I've tried so far: $email = 'someone@something.com'; $user_email = do_shortcode('[userinfo field="user_email"]'); echo var_dump(strcmp($user_email, $email) === 0); But the var_dump always returns false , I'm positive they are the exact same string! 回答1: By default the userinfo shortcode returns the data wrapped in a <span> tag. To suppress the span tag you can use

Call wordpress shortcode with AJAX

♀尐吖头ヾ 提交于 2019-12-14 01:03:47
问题 I would like to run shortcodes using a switch button. If the switch is " ON", I call a shortcode and if it is "OFF" I call another . As a test I tried calling a shortcode at the click on a single link with AJAX, it gives me this: File "page-recherche.php" : <a href="" id="clicklien">CLICK HERE</a> <script> $("#clicklien").click(function(e){ e.preventDefault(); $.ajax({ url: 'http://www.capitainebar.com/wp-content/themes/Capitaine-Bar/shortcode-recherche.php', success: function (data) { //

How to create a Wordpress Shortcode that does nothing?

点点圈 提交于 2019-12-13 07:26:09
问题 I'm trying to create a Shortcode to use as a wrapper so as to deflect the wpautop() function from coming into effect. Yes, I know how to remove the auto formatting in it's entirety but the goal is to create a custom Shortcode that I can wrap around an < img tag and circumvent the auto format in select cases. I've created this Shortcode : function no_wp_autoformat_shortcode() { return null; } add_shortcode('nowpautop', 'no_wp_autoformat_shortcode'); But when applied the image simply disappears

WordPress – How to use shortcode in php files

拥有回忆 提交于 2019-12-13 04:38:34
问题 After 2 days off digging in the code and after I've tried almost everything I know...I've come to the point where I either kick the project and bury it or someone can ignite the fire again and help me. I set up Wordpress with the WooCommerce Plugin and the products get looped out...all good till there. What I wanted to add is the possibility that visitors are able to upvote a product. So I was looking for a plugin and found one. But that's the actual problem! The Plugin called "Like-Photo"

Nested shortcode to dynamically display woocommerce products category

∥☆過路亽.° 提交于 2019-12-12 18:02:59
问题 I am attempting to display a woocommerce product category page based on the current user role. I have created a custom function get_user_role() to get the user role and added the shortcode [user_role] to fetch this. If I use the shortcode on a page it successfully returns "administrator" so I can confirm this custom shortcode is working. I am now having trouble using this shortcode as the category slug. So what I am trying to achieve is essentially the following: [product_category category='

css grid shortcodes and wrap in wordpress

[亡魂溺海] 提交于 2019-12-12 09:21:41
问题 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

Shortcode parser in C#

梦想的初衷 提交于 2019-12-12 06:49:36
问题 This question was probably asked before but there are no proper solutions, at least I am unable to find one. I have a CMS in C#, the article is saved in the database and what I need it while loading the article it should parse available shortcodes like Wordpress. string str = "Hello there, show my name as [shortcodeX val="Garth"]"; What I need is some help to parse it based on the shortcode called. public string shortcodeX(string val) { return "hi" + val; } string str =