Last active
March 8, 2022 14:47
-
-
Save donohoe/393a795b764a4adefeaa5b8960c23908 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
In Wordpress, using the "The SEO Framework" plugin, we want to break the inheritance | |
between the Meta Title and that of OpenGraph/Twitter Title (we also do this for Description but the approach is the same). | |
While the PHP code appears to work, the 'placeholder' | |
on the field INPUT and TEXTAREA elements still reflects the original behaviors. | |
This (hacky) code solves for that though a better approach is desired. | |
This would break if element IDs were to change in the future. | |
You also need to ensure you DO NOT run this code until the element exists. | |
Companion PHP code: | |
https://gist.github.com/donohoe/a6cfcf5e920e4e3ee29f2bedc1847a53 | |
*/ | |
function() { | |
var el = document.getElementById('tsf-inpost-box') || false; | |
if (el) { | |
var og_title = document.getElementById('autodescription_og_title') || {}; | |
var og_desc = document.getElementById('autodescription_og_description') || {}; | |
var tw_title = document.getElementById('autodescription_twitter_title') || {}; | |
var tw_desc = document.getElementById('autodescription_twitter_description') || {}; | |
var dekEl = document.querySelector('#row_dek_field textarea') || false; | |
var hedEl = document.querySelector('h1.wp-block-post-title') || false; | |
setInterval(function(){ | |
if (dekEl) { | |
og_desc.placeholder = dekEl.value; | |
tw_desc.placeholder = (og_desc.value.length > 0) ? og_desc.value : dekEl.value; | |
} | |
if (hedEl) { | |
og_title.placeholder = hedEl.innerText; | |
tw_title.placeholder = (og_title.value.length > 0) ? og_title.value : hedEl.innerText; | |
} | |
}, (1000/60)) | |
} else { | |
console.log('Hiding SEO plugin social placeholders'); | |
document.body.className += ' hide-seo-plugin-placeholders'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of using intervals, you may like to use the more advanced https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver.
For performance, I then recommend assigning in config only:
Perhaps even
attributes
can be set tofalse
because TSF invokes anonchange
event after every update -- though I'm not sure if that also invokes a mutation by default.