Per the comment under the OP’s question, below is the solution by using a return
instead of an echo
:
add_shortcode( 'phptest', 'custom_shortcode_phptest' );
function custom_shortcode_phptest() { // Add Shortcode
function generatePassword( $length = 6 ) {
$characters="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$charactersLength = strlen( $characters );
$pass="";
for ( $i = 0; $i < $length; $i++ ) {
$pass .= $characters[rand( 0, $charactersLength - 1 )];
}
return $pass;
}
$password = generatePassword();
$data = time();
$test="/home/blablabla/public_html/ot/docs/test/" . $password . '.txt';
$file = fopen( $test, "w" );
fwrite( $file, $data );
fclose( $file );
return 'Your pass is ' . $password . ' and it is valid for 3 days.';
}
Related Posts:
- PHP Deprecated: Non-static method should not be called statically
- Adding Custom Fields for Img in Posts
- How To Ignore a Filter On Applying Filter the Content In a Function
- Calling function from within functions.php returns unwanted value
- shortcode doesn’t work
- Can’t get custom posts of taxonomy to show
- get shortcode value
- Storing Options in a Shortcode
- How to remove html code in excel downloads using phpspreadsheet with wordpress plugins shortcode
- How to put JQuery/Ajax inside shortcode?
- WordPress Shortcode to get URL Parameters $_GET[‘name’] redirects for no reason at all
- WordPress function not being called from jQuery method
- Nested shortcode functions accessing variable
- Some code in shortcode function being ignored
- How to Create a shortcode to this php function
- Redirect to another page using contact form 7? [closed]
- What is @Action in WordPress?
- Custom shortcode for displaying user based on a role parameter
- Return multiple values in a shortcode attribute
- Is there a way to convert shortcodes to html content?
- Shortcode not working – quotes seems strange
- Get all the URLs of the pages that uses a specific shortcode
- Add the_post_thumbnail_url to a shortcode in function.php
- Echo out element to another page.
- Adding a Tag Parameter / Filter to My Shortcode
- Creating New Dynamic Fields for a Certificate (Number Generation, Code Referencing, and more)
- How to get current cart values using WC_Shortcodes?
- get_post_meta shortcode returns empty field
- How do I use a plugin’s shortcode attribute value in another function?
- Why does my custom plugin only function correctly once per page?
- Hide content for specific users with id
- Why is my shortcode not working?
- Get Shortcode output to database for static post_content
- Query Shortcode from a multisite to appear on a different site?
- Find all strings between an enclosing shortcode
- Posting code inside the post instead of in the template file using shortcode
- How to Set Limit with WordPress Get Bookmarks Shortcode
- Creating Features List in WordPress Post
- Integrate Razorpay quick payments plugin with contact form7 plugin
- cURL External API request displays content above other content on page
- Subtract Using GravityWP Count Plugin
- How to get URL param for pagination in shortcode?
- qTranslate‑X is not translating all shortcodes
- How to get the active theme’s slug?
- Preserve custom URL parameter on more pages
- if plugin is active? check if plugin is enabled or not?
- Making plugin unique to not conflict with plugins with the same name
- How to store ACF custom fields data in a custom table
- Trying to disable plugins doens’t work
- Have Plugin Handle Specific URLs
- Layout shop page: resize images and columns
- Can I use a Shortcode output as an HTML attribute value?
- Custom Post Type Plugin not loading category template and loading 404 instead
- Show history of post revisions on front end
- Plugin shortcodes not working in custom theme
- Set Post Format if find a string in title or post content
- wordpress site | All-in-one-cufon IE Issue
- creating html reusable blocks via shortcodes
- How to insert HTML/JavaScript form into WordPress page? [closed]
- My single.php page does not show the related data to the post which is clicked
- Creating a CSV with PHP inside the plugin directory
- pagination on data fetched using SQL query
- How to check if a taxonomy not exists in a plugin
- How passing values to construct function with Actions?
- Access a particular field in an array
- plugin shortcode not working on ajax request call
- wordpress add_action() issue in ajax call
- JQuery prepend a function
- I am trying to make a field show and save from quickedit screen
- Send email with list of active plugins upon activation/deactivation
- Form Plugin for Api Requests which is used via Shortcode
- eaccelerator PHP error
- Looking for a good way to include php code in posts, but using special include markup rather than direct php code
- Strange admin-ajax / CSS / $_SESSION issue
- How to add custom plugin data to the cart in woocommerce using custom button on product page?
- How to create admin setting for this small plugin
- Allowed memory size of 134217728 … wp-includes/wp-db.php on line 1989
- Undefined offset: 0 in WordPress after latest version upgrade [closed]
- Post source link plugin – small modification
- Make the product page as homepage WooCommerce
- How to use WordPress header function and footer function and not load word press database
- Hooking into the HTML header container
- Get Current Post ID in WP Loop For GiveWP
- Block plugin update possibilities (but not by hiding notifications)
- WP_get_image_editor resizing images in a foreach loop
- Conditional Fields depending on checkboxes
- Soflyy WP All Import Custom File Download Issue
- WordPress Admin sub-level menu issue
- Add class as plugin for other plugins
- Displaying friend’s posts only
- Shortcode registered from a plugin not recognized
- Strange get_the_* behavior with php 5.4
- Template from scratch: Sidebars not showing widget
- Contact Form 7: custom validation [closed]
- Enforce conditions only for draft posts using WyPiekacz, ignore pending and published posts
- White Screen When Includding A Folder With PHP Files
- How to show in front End images using Visual Composer attach_images?
- Shortcode inside a redirect [closed]
- wp_handle_upload – specified file failed upload test
- public custom posts not showing in my wordpress plugin