Dynamic Content Display
Professional WordPress plugin for dynamic content management with URL-based tab ordering, ACF integration, and persistent user preferences via cookies.
by Muhammad Waleed · github.com/mwaleed580/dynamic-content-display · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/mwaleed580/dynamic-content-display/archive/refs/heads/main.zipA professional WordPress plugin that serves different content to different users based on URL parameters, featuring dynamic tab ordering and persistent user preferences.
🚀 Features
- Dynamic Content Display: Serve different content based on URL parameters
- Tab Ordering: Dynamically reorder ACF repeater content sections
- Persistent Preferences: Cookie-based user preference storage
- Project-Specific Settings: Individual settings per project post
- Professional Architecture: Industry-standard OOP patterns and PSR-4 autoloading
📋 Requirements
- PHP 7.4 or higher
- WordPress 5.0 or higher
- Advanced Custom Fields (ACF) plugin
- Dynamic Content for Elementor (DCE) plugin
🔧 Installation
Via Composer (Recommended)
# Navigate to plugin directory
cd wp-content/plugins/dynamic-content-display
# Install dependencies
composer install --no-dev --optimize-autoloader
Manual Installation
- Upload the plugin files to
/wp-content/plugins/dynamic-content-display/ - Activate the plugin through the WordPress admin
- Ensure ACF and DCE plugins are installed and activated
📖 Usage
URL Parameters
Display Mode Parameter
?sr=up
Sets the display mode to "up" and stores preference in cookie for 24 hours.
Tab Ordering Parameter
?fe=info chat google-map
Reorders project tabs based on specified sequence (space-separated) and stores preference for 30 days.
Example URLs
# Basic tab ordering
/project/my-project/?fe=info chat google-map
# Alternative ordering
/project/my-project/?fe=api info additional-data
# Display mode
/project/my-project/?sr=up
# Combined parameters
/project/my-project/?fe=chat info&sr=up
ACF Field Structure
Create a repeater field named data_tabs with:
- Field Name:
data_tabs - Sub-field:
title(Text field)
🏗️ Architecture
Directory Structure
dynamic-content-display/
├── dynamic-content-display.php # Main plugin file
├── composer.json # Composer configuration
├── includes/
│ ├── Core/
│ │ └── Plugin.php # Main orchestrator class
│ ├── Services/
│ │ ├── CookieService.php # Cookie management
│ │ └── TabOrderingService.php # ACF and CSS logic
│ └── Traits/
│ └── Singleton.php # Singleton pattern implementation
└── vendor/ # Composer dependencies
Design Patterns
- Singleton Pattern: Ensures single instance of services
- Dependency Injection: Loose coupling between components
- Service Layer: Separation of concerns
- PSR-4 Autoloading: Industry-standard class loading
Classes Overview
Plugin (Core\Plugin)
Main orchestrator that initializes services and handles URL parameter processing.
CookieService (Services\CookieService)
Manages all cookie operations:
set_display_mode_cookie(string $mode): Sets display mode cookiesave_tab_order_cookie(int $post_id, string $tab_order): Saves tab orderget_tab_order_from_cookie(int $post_id): Retrieves tab orderhas_tab_order_cookie(int $post_id): Checks cookie existence
TabOrderingService (Services\TabOrderingService)
Handles ACF data processing and CSS generation:
add_tab_ordering_css(): Main method for CSS outputprocess_tabs_for_ordering(array $data_tabs, array $desired_order): Processes tab dataconvert_title_to_slug(string $title): Converts titles to slugsoutput_tab_ordering_css(array $tab_order, int $total_rows): Outputs CSS
Singleton (Traits\Singleton)
Provides singleton pattern implementation for all services.
🔄 How It Works
- URL Parameter Detection: Plugin detects
feorsrparameters - Cookie Storage: Parameters are stored in project-specific cookies
- ACF Data Processing: Retrieves
data_tabsrepeater field data - Title Conversion: Converts ACF titles to URL-friendly slugs
- Order Mapping: Maps URL parameter order to CSS element IDs
- CSS Generation: Outputs CSS with
orderproperties for reordering - Pattern Repetition: Applies same ordering to additional element sets
🎯 CSS Output Example
For URL ?fe=info chat google-map with 3 tabs:
.dce-elementor-rendering-id-2 { order: 1; } /* Info */
.dce-elementor-rendering-id-1 { order: 2; } /* Chat */
.dce-elementor-rendering-id-3 { order: 3; } /* Google Map */
/* Repeating pattern for additional sets */
.dce-elementor-rendering-id-4 { order: 1; }
.dce-elementor-rendering-id-5 { order: 2; }
.dce-elementor-rendering-id-6 { order: 3; }
🧪 Development
Setup Development Environment
# Install all dependencies (including dev)
composer install
# Run code style checks
composer run cs
# Fix code style issues
composer run cbf
# Run tests
composer run test
Adding New Features
- Follow PSR-4 autoloading standards
- Use dependency injection for service communication
- Implement singleton pattern for services
- Add only required methods (no bloat)
- Follow WordPress coding standards
🔒 Security
- All user inputs are sanitized using
sanitize_text_field() - Direct file access is prevented
- Proper nonce validation (where applicable)
- Secure cookie handling
🐛 Troubleshooting
Common Issues
CSS not applying: Ensure ACF field name is exactly data_tabs
Cookies not saving: Check PHP session and cookie settings
Autoloader errors: Run composer dump-autoload -o
Debug Mode
Add to wp-config.php for debugging:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
📝 Contributing
- Fork the repository
- Create a feature branch
- Follow coding standards
- Add tests for new features
- Submit a pull request
📄 License
This plugin is licensed under the GPL v2 or later.
👨💻 Author
Muhammad Waleed
- LinkedIn: mwaleed580
- GitHub: mwaleed580
🙏 Acknowledgments
- WordPress community for excellent documentation
- ACF team for the powerful custom fields plugin
- DCE team for dynamic content capabilities