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
- How to add a shortcode button to the TinyMCE editor?
- How to change a user’s password programatically
- 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?
- What is the correct way for a theme to support plugin UIs?
- How does WordPress determine the primary plugin PHP file?
- translation does not work with text_domain
- Editor not displaying dynamically after clicking on the button
- Publish Post After Click On A Link
- Custom url structure for custom template
- How to submit documentation with plugin
- Having separate plugins and themes folder for multi-site setup
- 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?
- How can plugins have their own pages?
- Reusable functions and tools (Framework)
- Woocommerce – How to populate custom select field with stored values on checkout page?
- How to create ‘import dummy data’ option in custom wordpress plugin
- Creating a plugin to sanitize comment and the url field before display only
- Object Oriented Plugin not working
- How to toggle between two custom fields in WordPress woocommerce ‘WC Product Field Group’ plugin?
- 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 change the name of the “edit my profile” link in the WordPress admin backend
- Change the display of Settings API (do_settings_sections)
- WordPress Jquery UI Spinner
- How can I modify admin bar only if my plugin is loaded
- Adding custom meta boxes to specified custom post type
- How can I add IP address to my post?
- add seperate suffix for low price and high price in woocommerce
- How to add/change (woocommerce) product tab icon
- How to write to a separate PHP file in plugin settings
- Best way to retrieve data in custom api extended from wp-api
- Custom CSS not being added by plugin
- How to set the default value as the saved value once a form of widget is saved?
- How do i specify a url to which to redirect the user after he logs out from facebook?
- How to show multi line output from metabox
- How to keep plugin (media-sync) running even the tab is closed?
- How does the WP repository determine that two plugins are the same when counting active installs?
- Need to edit author permissions | custom taxonomy
- Where do I put the code snippets I found here or somewhere else on the web?
- Is it possible to pin a post in second position from top
- Visual composer custom element error
- admin_notices show after load completed
- Activate Plugin Automatically After Set Time
- function post to trash problem
- How to call function in WordPress on button click?
- how to add a hidden type input to wp admin login form programmatically
- How can I see $post object in frontend from functions.php?
- Move plugin pages from dashboard to front-end
- Allow members to create groups on my site
- when i activate my WordPress plugin cannot see customizer options or preview
- Get post content inside plugin class method
- Plugin Options Page and Subpage
- If I am not writing a theme, how do I add custom fields to a user for a plugin
- Protect WordPress option value
- Plugin: Translated plugin is “not translated”
- Ubermenu 3 Nav Bar Customization
- Add Flatr button to Sharing option
- Change localization only for plugin
- How to get author developer link on plugin page
- wp_schedule_event need to deactivate plugin changing recurrance
- A more elegant way to handle notices/warnings
- Redirect default login page to a custom page [duplicate]
- appointment plugin doesn’t display all appointments
- Doing action based on input from options menu
- Create New Admin Menu Section – Like how custom post type works, in a way
- Customize Multi-Column Tag Map to fetch specific post-type
- Combining JS files to one script
- What are the downsides of using bootstrap in plugin development?
- How ACF Advanced Custom Field works with Woocommerce Single Product [closed]
- How to generate a responsive output from plugin?
- The plugin generated xxx characters of unexpected output during activation
- Upload Image to desired directory through plugin
- Unable to pass arguments from plugin form to filter hook using ajax, the data is transferring via ajax but unable to pass as arguments in filter hooks
- How to update changes to multiple sites at the same time
- Why am I getting an error when requiring a file in my plugin?
- Running a function using Crown WordPress on one day a week, for example, Mondays of every week