Random Text Display Plugin

Random Text Display Plugin Documentation

Overview

The Random Text Display plugin allows you to display random text snippets anywhere on your WordPress site using a simple shortcode. Each time a page loads, a different text will be displayed from your predefined collection of texts.

Features

  • Easy management of text snippets through WordPress admin panel
  • Simple shortcode implementation
  • AJAX-based text loading for better caching compatibility
  • Inline text display that integrates seamlessly with existing content
  • Full internationalization (i18n) support
  • Error handling and logging

Installation

  1. Download the plugin files
  2. Upload the plugin folder to the /wp-content/plugins/ directory of your WordPress installation
  3. Activate the plugin through the ‘Plugins’ menu in WordPress
  4. If needed, install language files in the /languages directory

Usage

Adding Text Snippets

  1. Go to Settings -> Random Text in your WordPress admin panel
  2. In the “Add New Text” section, enter your text in the textarea
  3. Click “Add Text” to save
  4. View all your saved texts in the table below the form

Displaying Random Text

Use the shortcode [random_text] anywhere you want to display a random text: – In posts – In pages – In widgets (if shortcodes are enabled for widgets) – In templates (using do_shortcode())

Examples

// In a post or page:
This is some content with a [random_text] inside.

// In a template file:
<?php echo do_shortcode('[random_text]'); ?>

Deleting Text Snippets

  1. Go to Settings -> Random Text
  2. Find the text you want to delete in the table
  3. Click the “Delete” button
  4. Confirm the deletion

Translations

Available Translations

The plugin comes with: – English (default) – Translation template file (.pot)

Adding New Translations

  1. Copy the template file (random-text-display.pot) from the languages folder
  2. Create a new .po file for your language (e.g., random-text-display-fr_FR.po)
  3. Translate the strings using a PO editor (like Poedit)
  4. Generate the .mo file
  5. Place both .po and .mo files in the languages directory

File Structure

random-text-display/
├── languages/
│   ├── random-text-display.pot
│   ├── random-text-display-{locale}.po
│   └── random-text-display-{locale}.mo
└── random-text-display.php

Creating Custom Translations

  1. Open the .pot file with a PO editor
  2. Choose your target language
  3. Translate all strings
  4. Save as both .po and .mo files
  5. Name files according to locale (e.g., random-text-display-de_DE.po)

Technical Details

Plugin Information

Plugin Name: Random Text Display
Plugin URI: https://nkedem.net/random-text-display/
Description: Display random text using shortcode.
Version: 1.0
Author: Nemrod Kedem
Text Domain: random-text-display
Domain Path: /languages

Database

The plugin creates a custom table in your WordPress database:

{prefix}_random_texts
- id (mediumint, auto-increment)
- text_content (text)

Shortcode Implementation

The plugin uses: – AJAX to load texts dynamically – Inline <span> elements for seamless text integration – WordPress nonces for security – Error logging for troubleshooting

Functions Reference

  • rtd_load_textdomain(): Loads translation files
  • rtd_activate(): Runs on plugin activation, creates database table
  • rtd_admin_menu(): Adds the settings page to WordPress admin
  • rtd_get_random_text(): AJAX handler for retrieving random text
  • rtd_shortcode(): Processes the [random_text] shortcode
  • rtd_uninstall(): Cleanup on plugin uninstallation

Troubleshooting

Common Issues

  1. Text Not Displaying
    • Check if JavaScript is enabled
    • Check browser console for errors
    • Verify texts exist in the database
  2. Same Text Appears
    • Clear your browser cache
    • Clear your WordPress cache
    • Clear your server cache
  3. Database Errors
    • Check WordPress debug log
    • Verify database permissions
    • Ensure table was created properly
  4. Translation Issues
    • Verify correct language files exist
    • Check file naming conventions
    • Confirm WordPress language setting

Error Logging

The plugin logs errors to the WordPress debug log when: – Database table creation fails – Text retrieval fails – Database operations fail

Security Considerations

The plugin implements: – Data sanitization for all inputs – SQL preparation for database queries – Access control for admin functions – XSS prevention in output – Proper text domain handling

Uninstallation

  1. Deactivate the plugin
  2. Delete the plugin through WordPress admin
  3. The plugin will automatically remove its database table
  4. Language files will be removed with plugin deletion

Support

For issues and support: 1. Check the troubleshooting section 2. Review WordPress debug logs 3. Contact plugin support at https://nkedem.net/random-text-display/

Version History

  • 1.0: Initial release
    • Basic text management
    • Shortcode implementation
    • AJAX loading
    • Error handling
    • Internationalization support

Requirements

  • WordPress 5.0 or higher
  • PHP 7.0 or higher
  • MySQL 5.6 or higher

License

This plugin is released under the same license as WordPress (GPL v2 or later).

דילוג לתוכן