<?php // Shortcode for Table of Contents function custom_table_of_contents() { global $post;
// Get content of the post $content = $post->post_content;
// Match all headings (h2, h3, etc.) preg_match_all('/<h([2-4])>(.*?)<\/h\1>/', $content, $matches, PREG_SET_ORDER);
if (!$matches) { return ''; // Return empty if no headings found }
// Start TOC list $toc = '<div class="custom-toc">'; $toc .= '<h2>Table of Contents</h2>'; $toc .= '<ul>';
// Loop through each heading and add to TOC foreach ($matches as $match) { $heading_text = strip_tags($match[2]); $anchor = sanitize_title($heading_text);
// Add anchor link to each heading in TOC $toc .= '<li><a href="#' . $anchor . '">' . $heading_text . '</a></li>';
// Add anchor ID to each heading in the content $content = str_replace($match[0], '<h' . $match[1] . ' id="' . $anchor . '">' . $match[2] . '</h' . $match[1] . '>', $content); }
// End TOC list $toc .= '</ul></div>';
// Update the post content with new anchors $post->post_content = $content;
return $toc; }
// Register shortcode in WordPress add_shortcode('toc', 'custom_table_of_contents'); ?>
Forex trading involves the exchange of currencies and operates 24/5, characterized by high liquidity and leverage options. New traders should understand core concepts such as margin, trading strategies, and market analysis. Success requires continuous learning, risk management, and starting with a demo account to build confidence before live trading.