You don’t, alert is a javascript function that runs in the browser. PHP runs on the server, the two are different languages that run in different places.
Instead, consider using script tags:
return '<script>window.alert("Connected to the database successfully.")</script>';`
console.log("") may be a more appropriate method than alert("") for debugging
I would also note, that shortcodes embed content, and should represent something. Your plugin appears to create graphs, therefore I would assume your shortcode should be something such as [vivek_graph]. Inside that shortcode you can connect to the database, rather than requiring a connect to db shortcode happen before every use
Related Posts:
- How can I save repeatable fields with one value inside an array?
- Plugin not saving values when placed in a folder within /wp-content/plugins
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- Redirect to another page using contact form 7? [closed]
- How to Resize the Custom Post Images?
- Amazon.com intergration with WordPress?
- Custom Fields for Page Edits
- Table of contents (TOC) plugin is not showing header tag
- Create multiple posts when a custom post is created
- How to get post that has non zero or greater than zero meta value
- Creating Nested custom fields
- Problem with conditional woocommerce custom checkout field
- Creating a user ‘add custom field’ section
- Synch Custom Post Types (and Custom Fields, Cats, etc.) Between WordPress Sites
- WordPress Meta Query: Relation is not working correctly
- Integrating WordPress Content into a jQuery Slider
- Outputting custom field query from a plugin to the website header
- Need to add custom cart item data
- What’s the preferred method of writing AJAX-enabled plugins?
- How to add a shortcode button to the TinyMCE editor?
- How to change a user’s password programatically
- Who are the most trusted plugin developers? [closed]
- Redesigning Custom Post Type “Add New” page
- Plugin upgrading: Widget settings
- Create a table in custom plugin on the activating it?
- How would you require and automatically download dependent plugins?
- How to delete custom taxonomy terms in plugin’s uninstall.php?
- Redirect to settings page after install
- Is there any record of installed plugins in the database?
- Using require_once in a Plugin?
- What is the correct way for a theme to support plugin UIs?
- How to call “page specific menu items” in template [closed]
- How does WordPress determine the primary plugin PHP file?
- Custom headers for the WordPress plugin directory
- plugin wants to update to wrong plugin
- translation does not work with text_domain
- How can I add a custom header to a custom template in a plugin without using the theme folders
- Trying to avoid including wp-load.php
- AJAX Call Via Vanilla JavaScript In WordPress Plugin Development
- Understanding apply_filters
- Editor not displaying dynamically after clicking on the button
- Custom values are not translated
- Make the plugin directory recognize new version numbers
- Master menu item for multiple plugins?
- Publish Post After Click On A Link
- Custom url structure for custom template
- Change the name of an installed plugin
- Where do I add a new table’s name in wpdb?
- flush_rewrite_rules() not working on plugin activation
- Determine plugin name from within plugin_action_links filter
- How to create popup same as wordpress popup feature
- How to submit documentation with plugin
- Having separate plugins and themes folder for multi-site setup
- How to customize user search
- Upgrade Private Plugin without Deleting
- Placement of Code in Plugin for hooking `save_post`
- gallery option is not available in media upload box in costum theme option page
- Many plugins making WordPress run slow by design?
- Sanitizing, Validating and Escaping in WordPress (Plugin)
- How to make first_name and last_name required fields in user profile?
- Making my plugin translation ready. Poedit not working
- How can plugins have their own pages?
- How do I turn a custom post type into a plugin?
- like to keep reading plugin
- Check if email address exists front end with AJAX in a plugin
- Avoiding Duplicate function names in Post Loop (WP_Footer script)
- Can we use a webservice with WordPress?
- WooCommerce get_price returning wrong price when used via ajax
- Open Post Thumbnail in New Child Theme File in WordPress
- Reusable functions and tools (Framework)
- Add keywords meta to index.php page
- How I can get custom field’s current value?
- Woocommerce – How to populate custom select field with stored values on checkout page?
- How to create ‘import dummy data’ option in custom wordpress plugin
- New User Form – Custom Menu Page
- Checking instances of scripts in wp_head
- Creating a plugin to sanitize comment and the url field before display only
- Object Oriented Plugin not working
- Does WP identify plugin by plugin name or plugin_basename?
- Creating mySQL procedure with $wpdb
- Fetch Children of Grouped Products Inside WooCommerce Product Loop
- How can I prevent my plugin go development trunk [closed]
- How to toggle between two custom fields in WordPress woocommerce ‘WC Product Field Group’ plugin?
- Modifying Author Link to add Author Meta in URL
- Best way to maintain and update 3rd-party WP plugin when developer is unresponsive?
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- Best place for if/else piece of code related to custom plugin?
- How do you assign a UUID to posts/products/comments/reviews?
- How to make a implement queue for scheduling tasks in WordPress?
- What are the specifics of WordPress development I need to know? [closed]
- Insert data from .sql file in wordpress plugin
- How can i get the post’s full html source by its ID?
- Force file download on plugin activation
- how to do login using woocommerce rest api From android
- How to create a code editor for my plugin .?
- Editable form for WordPress plugin options page
- How to create a custom post type that contains another custom post type?
- Manually set a custom admin sub-menu selected?
- wp-pagenavi getting 404 page not found
- remove add new post, if there is already one post