Guest User

Untitled

a guest
Jan 2nd, 2025
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. add_action( 'admin_footer-post.php', function () {
  2. ?>
  3. <script type="text/javascript">
  4. (function ($) {
  5. wp.hooks.addFilter('rank_math_content', 'rank-math', function (content) {
  6. return content.replace(/\[woodmart_title\s+([^\]]+)\]/g, function (match, attrString) {
  7. const parseAttributes = (str) => {
  8. const attrs = {};
  9. const regex = /(\w+)=(["'])(.*?)\2/g;
  10. let m;
  11. while ((m = regex.exec(str)) !== null) {
  12. attrs[m[1]] = m[3];
  13. }
  14. return attrs;
  15. };
  16.  
  17. const attrs = parseAttributes(attrString);
  18.  
  19. const tag = attrs.tag || 'h4';
  20.  
  21. if (attrs.title) {
  22. const wrappedTitle = `<${tag}>${attrs.title}</${tag}>`;
  23.  
  24. const newAttrString = attrString.replace(/title=(["'])(.*?)\1/, `title="${wrappedTitle}"`);
  25.  
  26. return `[woodmart_title ${newAttrString}]`;
  27. }
  28.  
  29. return match;
  30. });
  31. }, 9);
  32. })(jQuery);
  33. </script>
  34. <?php
  35. });
Advertisement
Add Comment
Please, Sign In to add comment