Shortcode to include PHP file, pass various parameters to include?

Thanks for your comments and guidance. I implemented solutions which didn’t reinvent the wheel. The complication was finding a way to remove the [insert_php][/insert_php] wrapped code from pages and posts and still preserve the content and user experience. Custom Template Pages Pages and Posts which were almost entirely PHP were made into custom template files. … Read more

Adding a wp_head hook from an included PHP file

To enqueue styles and scripts properly, use the wp_enqueue_scripts action like so: function wpa_63708_enqueue_scripts() { wp_register_script( ‘my-script’,’/path/to/script’ ); wp_enqueue_script( ‘my-script’ ); } add_action( ‘wp_enqueue_scripts’, ‘wpa_63708_enqueue_scripts’ );

Shortcode return is printing a 1 afterward

You are returning the result of calling include. You want to grab the output of the included file and return than instead. Use output buffering to do that. function build_total_search_method( $atts ) { ob_start(); include( dirname(__FILE__) . “/includes/total_search.php” ); $shorcode_php_function = ob_get_clean(); return $shorcode_php_function; } add_shortcode( ‘total_search’, ‘build_total_search_method’ );

Shortcode not passing variable to included file

Ok, so somehow I got it working by changing it to this: It looks like it didn’t like ‘the_clientId’. Maybe it just doesn’t like capital letters???? [insert-form form_location=”form.php” identification_number=”12345″] function insert_the_form($atts){ $form_base = plugin_dir_path(__DIR__); // Shortcode attributes & options $atts = shortcode_atts( array( ‘form_location’ => ‘NULL’, ‘identification_number’ => ‘NULL’ //Variable for client ID ), $atts, … Read more

Dynamically determine URI to scripts and styles included with a class which could be added from plugin/theme/child theme/mu plugin

For plugins it is: $plugin_url = plugin_dir_url( __FILE__ ); This works even if wp-content is on a separate domain. You may get problems if your class is in a subdirectory of the plugin – you should probably make the __FILE__ a parameter for a function: public function get_plugin_url( $base = __FILE__ ) { return plugin_dir_url( … Read more