shortcode

Wordpress remove shortcode from content

混江龙づ霸主 提交于 2019-12-04 16:30:51
Is it possible to remove the gallery shortcode from the content before when the_content() is executed? I searched codex and found remove_shortcode( $tag ) but they show no examples. I tried adding to functions function remove_gallery($content) { $content .= remove_shortcode('[gallery]'); return $content; } add_filter( 'the_content', 'remove_gallery', 6); It doesnt work.. Update: I was able to unregister the shortcode using the code below, but it also removes the content function remove_gallery($content) { return remove_shortcode('gallery', $content); } add_filter( 'the_content', 'remove

How to use wc_customer_bought_product function to check if customer bought product in an array

旧巷老猫 提交于 2019-12-04 06:08:35
问题 First of all, I am a beginner and new to php so please forgive my ignorance. I asked my first question on stackoverflow today and somebody was kind enough to provide a great solution, so I am giving this another try. I am trying to use a function to check if a customer bought a product inside an array of product ids as in his account pages when logged in I need to display a different menu if he bought product from array A or product from array B, array C, you get it. I would like to create a

WordPress Orderby Last Word In Title

北城以北 提交于 2019-12-04 05:04:50
I have a custom post type of "staff". I need to get this to display the staff alphabetically by last name on the page. I know a work around would be to use custom meta boxes and break up first and last names into two fields but I'm trying to avoid that as that seems very hackish and not as clean as just using the title field. I have a shortcode working that will show the custom post type with the staff "type" taxonomy attribute requested. Here is an example: [staff type="local"] I can't just assume that it's the second word in the title that I want since some staff are couples and will have

Wordpress using echo vs return in shortcode function

拈花ヽ惹草 提交于 2019-12-04 03:08:30
I just found out that both echo and return works fine for displaying content from a shortcode function. function foobar_shortcode($atts) { echo "Foo Bar"; //this works fine } function foobar_shortcode($atts) { return "Foo Bar"; //so does this } I just want to know, is there any difference between using either of these? If so what's the recommended one? I normally use echo in this case; is it okay? Nathan Dawson Echo may work in your specific case but you definitely shouldn't use it. Shortcodes aren't meant to output anything, they should only return content. Here's a note from the codex on

Dynamic shortcodes and functions in WordPress

社会主义新天地 提交于 2019-12-03 20:48:08
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) { function route_sc$route->id () { return "<div>Route $route->id</div>"; } add_shortcode('route $route->id

how to insert shortcode into wordpress menu

三世轮回 提交于 2019-12-03 13:53:11
问题 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', 'do_shortcode', 7); Or maybe someone knows this is not possible and can tell me. /* Nav Menu */ function add_profile_link_to_nav(){ if ( is_user_logged_in() ) { ?> <ul> <li class="menu-item"id="one"> <a href="http://example.com/members/">All Members</a>

Wordpress shortcodes pass array of values

安稳与你 提交于 2019-12-03 12:23:58
问题 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( 'href1' => '#jl1', 'href2' => '#jl2', 'href3' => '#jl3', 'href4' => '#jl4', ), $atts)); return '<div id="internalPageMenu"> <ul> <li><a href="' . $href1 . '"><i class="fa fa-bars"></i>link 1</a></li> <li><a href="' . $href2 . '">link 2</a></li> <li><a href="

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

核能气质少年 提交于 2019-12-03 10:37:07
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'); Try inserting this code in your functions.php file: remove_filter( 'the_content', 'wpautop' ); add_filter( 'the_content', 'wpautop', 99 ); add_filter( 'the_content', 'shortcode_unautop', 100 ); add_filter('the_content

how to insert shortcode into wordpress menu

泪湿孤枕 提交于 2019-12-03 03:24:38
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', 'do_shortcode', 7); Or maybe someone knows this is not possible and can tell me. /* Nav Menu */ function add_profile_link_to_nav(){ if ( is_user_logged_in() ) { ?> <ul> <li class="menu-item"id="one"> <a href="http://example.com/members/">All Members</a> <ul class="sub-menu"> <li class="menu-item"><?php echo custom_execute_shortcode(); ?> </li> </ul> </li>

How to create a shortcode/edit a function to solve the conflict between Bootstrap and wpautop in Wordpress

帅比萌擦擦* 提交于 2019-12-02 22:39:49
问题 Following on from my previously unsolved question How to show Bootstrap Buttons inline instead of one per line in Wordpress Specifically? and after extensive research in this point, I found out that that there is a conflict between Wordpress and Bootstrap. Wordpress simplified the text editing process by introducing invisible line breaks < /br> after each line. When Using Bootstrap elements (e..g buttons) with Wordpress, a line break < /br> gets introduced after each button code, leading them