Convert my php code into shortcode

The basics of creating a shortcode are quite simple. You just need to create a function that returns the code you want to output in a string and register that function: function wpse_143641_homebox_shortcode( $atts ) { return <<<HOMEBOX <div class=”homebx01 clearfix ani-1″> <div class=”homebxhead clearfix”> <div class=”bxicon homebxicon01″></div> <div class=”bxheadtxt”>Category name</strong></div> </div> <div class=”cl”></div> <div … Read more

Using $this from child class inside shortcode function

Your issue is in the callable object you add: array( __CLASS__, “build_shortcode”) This translates to: array( “WC_Product_Categories”, “build_shortcode”) Which is equivalent to: WC_Product_Categories::build_shortcode(); But build_shortcode is not a static function/method, and static functions/methods do not have a $this object, because there is no object associated. What you actually want is: array( $this, ‘build_shortcode’ ) Which … Read more

Page code showing in WP Dashboard

Shortcodes should not echo any output. They should always return the text that is to be used to replace the shortcode. You either write the html code on a variable: function my_shortcode() { $output=”<div>something</div>”; return $output; } Or you can use php output buffering: function my_shortcode() { ob_start(); ?> <div>something</div> <?php return ob_get_clean(); } In … Read more

Code is providing a row of data but not formatting it as table

It’s not displayed as table, because you don’t return correct HTML code. Let’s take a look at your code (I’ve put comments at end of incorrect lines): $content=”<table>”; $content .= ‘</tr><th>Week Beginning</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th><th>Sunday</th><th>Weekly Total</th><th>Previous Week Totals</th></tr>’; // <- here you open TR with </tr>, so it’s already incorrect $results = $seconddb->get_results( ‘ SELECT * FROM seconddb_PontoonBoats_LineOne_2Log’ … Read more

Just display content between shortcode brackets

I have good news: the answer is simple. The WordPress Codex concerning Enclosing Shortcodes (like the one you posted here) shows that the shortcode callback has 2 arguments, $atts and $content. You want to work with $content: function wporg_shortcode($atts = [], $content = null) { // do something to $content // always return return $content; … Read more