Shortcode Output Always Before Content [duplicate]

Return the HTML instead of the echo function dataservices_category($atts) { // Attributes extract(shortcode_atts(array( ‘id’ => ” ), $atts)); $html = “”; // Code if (isset($id)) { $categories = get_categories(‘child_of=” . $id); foreach ($categories as $category) { if ($category->parent != $id) { $html .=”<div style=”margin-left:50px;”>’; $html .='<h4>’ . $category->name . ‘</h4>’; } else { $html .='<h3>’ … Read more

WordPress Shortcode loads at the top

First, declare your variable: $return = ”; Then, throughout the code, concatenate items: $return .= ‘<div class=”sp shadow”><img src=”https://wordpress.stackexchange.com/questions/81864/…”></div>’; $return .= ‘<h3>Videos</h3>’; And finally, return the result: return $return;

Is there a way I can return terms by name using a shortcode?

This is the solution to get post terms by taxonomy by shortcode: /** * Custom shortcode to get terms */ function ALC_post_terms_by_taxonomy( $atts ) { global $post; $taxonomyTerms = wp_get_post_terms( $post->ID, $atts[‘taxonomy’], ‘orderby=name&hide_empty=0’ ); $term_array = array(); foreach ($taxonomyTerms as $taxonomyTerm) { $term_array[] = $taxonomyTerm->name; } return implode( ‘, ‘, $term_array ); } add_shortcode(‘get_terms_by_taxonomy’, ‘ALC_post_terms_by_taxonomy’); … Read more

style css to header for shortcodes

You can insert any code in the header by hooking an action. header.php <?php wp_head(); ?> functions.php add_action( ‘wp_head’, ‘iulia_example’ ); function iulia_example() { echo ‘<style type=”text/css”> .sc_title {color:#fff; font-weight:600;} </style>’; } the result will be : the style inserted just above </head>

Add a short code to a plugin

Here is the code that you need to pull content from a wordpress page you will require the id number of the page and add it into the shortcode. [example page_id=”21″][/example] function example_shortcode( $atts, $content = null) { extract( shortcode_atts( array( ‘page_id’ => ” ), $atts ) ); // Will display our page content of … Read more

How to not show shortcode contents if cart is empty?

You can check the carts content then show the cart if it has some items // Add a WooCommerce Cart Total shortcode [cart_total] add_filter(‘woocommerce_add_to_cart_fragments’, ‘woocommerce_header_add_to_cart_fragment’); function woocommerce_header_add_to_cart_fragment( $fragments ) { global $woocommerce; ob_start(); ?> <a class=”cart-contents” href=”https://wordpress.stackexchange.com/questions/274073/<?php echo $woocommerce->cart->get_cart_url(); ?>” title=”<?php _e(‘View your shopping cart’, ‘woothemes’); ?>”><i class=”fa fa-shopping-cart “></i>&nbsp;<?php echo $woocommerce->cart->cart_contents_count;?></a> <?php $fragments[‘a.cart-contents’] = … Read more