Add bootstrap to a custom plugin.
-
Hello, I need some help. I’m developing a plugin and I need to use Bootstrap on the shortcodes.
I download Bootstrap and upload it to my-plugin/public/css folder.
Then I create the function to load the styles, scripts and the shortcode.
private function define_public_hooks() {
$plugin_public = new My_Wp_Tools_Public( $this->get_plugin_name(), $this->get_version() );$this->loader->add_action( ‘wp_enqueue_scripts’, $plugin_public, ‘enqueue_styles’ );
$this->loader->add_action( ‘wp_enqueue_scripts’, $plugin_public, ‘enqueue_scripts’ );// Add a shortcode to home page.
$this->loader->add_action(‘mwpt-most-popular-today’, $plugin_public, ‘mwpt_most_popular_today’);
add_shortcode(‘mwpt-most-popular-today’, array( $plugin_public, ‘mwpt_most_popular_today’));
}Here is the functions to load styles and scripts:
public function enqueue_styles() {
wp_register_style( ‘bootstrap-css’, plugin_dir_url( __FILE__ ) . ‘css/bootstrap-4.1.0/dist/css/bootstrap.full.css’, array(), ‘1.0.0’, all);
wp_enqueue_style(‘bootstrap-css’);
}
public function enqueue_scripts() {
wp_register_script(‘bootstrap-js’, plugin_dir_url( __FILE__ ) . ‘css/bootstrap-4.1.0/dist/js/bootstrap.full.js’, array(‘jquery’), ‘3.3.1’, true);
wp_enqueue_script(‘bootstrap-js’);
}And the function to create a shortcode example using bootstrap:
function mwpt_most_popular_today($content) {
$html = ‘<br><div class=”alert alert-success”>Success! Indicates a successful or positive action.</div>’;
return $content . $html;
}For some reason the bootstrap its not styling the $html variable, what I’m doing wrong?
Best regards.
- The topic ‘Add bootstrap to a custom plugin.’ is closed to new replies.