nonethefewer: (Default)
[personal profile] nonethefewer

When I post in Wordpress, I use Visual for appearance and forcing double-spaces, but I use HTML for adding links and being very picky with my code.  Here's how to add a button in the HTML editor bar to not only add LJ user code, but to have it plug in the username in the right spots.

0) You will be editing the /wp-includes/js/quicktag.js file.  Make backups, &c &c.

1) Open the file and look for the first instance of this line: edButtons[edButtons.length]

Underneath that code block (should be for the 'strong' tag), add this:

edButtons[edButtons.length] =
    new edButton('ed_lj'
    ,'LJ User'
    ,'<a href="http://###.livejournal.com/profile"><img style="margin: 0px; vertical-align: middle;" title="ljuser" src="[img src]" alt="ljuser" border="0" width="17" height="17"></a><a href="http://###.livejournal.com/"><strong>###</strong></a>'
    ,"
    ,'ljuser'
);

If you stop and save at this point, you will have a button that will add the LJ user code.  ### should be replaced with the user name, and [img src] should be replaced with where you've saved the 17×17 LJ user icon.  (I recommend saving it locally.)

However, I want it to ask for and insert the username, so I don't have to.  So…

2) Search for this string: function edShowButton(button, i) {

You should see an if/else if/else block.  Insert this code above the else if line:

else if (button.id == 'ed_lj') {
    document.write('<input id="' + button.id + '" class="ed_button" onclick="edInsertLJUser(edCanvas, ' + i + ');" type="button" value="' + button.display + '" accesskey="' + button.access + '" />');
}

3) Search for this string: function edInsertLink(myField, i, defaultValue) {

Below that function (and above the edInsertImage function), add this code block:

function edInsertLJUser(myField, i, defaultValue) {
    if (!defaultValue) {
        defaultValue = 'news';
    }
    if (!edCheckOpenTags(i)) {
        var theUser = prompt(quicktagsL10n.enterURL, defaultValue);
        if (theUser) {
            edButtons[i].tagStart = '<a href="http://' + theUser + '.livejournal.com/profile"><img style="margin: 0px; vertical-align: middle;" title="ljuser" src="[img src]" alt="ljuser" border="0" width="17" height="17"></a><a href="http://' + theUser + '.livejournal.com/"><strong>' + theUser + '</strong></a>';
            edInsertTag(myField, i);
        }
    }
    else {
        edInsertTag(myField, i);
    }
}

4) Finally, save, close, and refresh the Add New Post or Edit Post page.  When you click on the HTML tab now, you should see LJ User.  Click on that, and where it says 'news' (the default LJ user), put in the LJ username you want to enter in.  This will return code that (a) has the username in all the right places and (b) looks right both in WP and LJ.

Ta-da!

Originally posted at Xtinian Thoughts.  Comment here or there.

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

February 2022

S M T W T F S
  12345
6789101112
13141516171819
20212223242526
2728     

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 22nd, 2025 05:12 am
Powered by Dreamwidth Studios