Display Data in Table from External Database in WP using Shortcodes

While it is VERY bad practice to have spaces in the object names, there are times where it may be out of your control. You can use the syntax of $object->{‘Property Name’}, like this: // add the shortcode [pontoon-table], tell WP which function to call add_shortcode( ‘pontoon-table’, ‘pontoon_table_shortcode’ ); // this function generates the shortcode … Read more

Shortcode from a function not working

If you refer to the documentation for add_shortcode, you need your function to return the content: function uniquetestfunction($attributes) { return ‘<div class=”my_class”>Test Element</div>’; } add_shortcode(‘uniqueshortcodename’,’uniquetestfunction’); You also used the wrong quotes in your add_shortcode line – stick with single ‘ or double ” quotes.

Add code to Functions.php

Yes. It’s best practice to use a child theme and make your modifications there rather than edit the parent theme directly. This will allow you to to make changes without fear of overwriting your customizations. From the Codex: A child theme inherits the look and feel of the parent theme and all of its functions, … Read more

Best way to use a large array in function

If it’s just a list of numbers, I’d suggest just saving them in a text file, with a number on each line. 110019 111222 112233 Then when you need the file, read its contents with PHP, and use preg_split() to turn it into an array: $file_path = plugin_dir_path( ‘postcodes.txt’, __FILE__ ); // Or wherever you’ve … Read more

Run a code only on theme activation only during first activation

What about using WordPress Options API to store a flag whether it is the first switch or not: https://codex.wordpress.org/Options_API <?php add_action(‘after_switch_theme’, ‘setup_theme_options’); function setup_theme_options () { if(get_option(‘first_theme_activation’) === false){ // Set a flag if the theme activation happened add_option(‘first_theme_activation’, true, ”, false); // stuff here only runs once, when the theme is activated for the … Read more