Code Display Problem

Hi,

I want to add below code with [x_code] shortcode in my post but it displays like on screenshot. Post link is this https://www.soruncozumu.com/target_blank-yerine-relexternal-kullanimi/

function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];
        if (
            anchor.getAttribute("href") && (
            anchor.getAttribute("rel") == "external" ||
            anchor.getAttribute("rel") == "nofollow" ||
            anchor.getAttribute("rel") == "external nofollow" ||
            anchor.getAttribute("rel") == "nofollow external" )
            )
        anchor.target = "_blank";
    }
}
window.onload = function() {
    externalLinks();
}

Hi There,

Thanks for sending us the issue.
Seems the code also not working for me. I checked in my local setup and its gives the same output as you have.
This might be a bug or the code which you want to show having issue. I will validate it with our team.

To display code in post here is a nice article to help you.


Please let me know if it helps.

Thanks

I found a solution for now, the code I want to add in my post content was a javascript code and I added below tag to my code. I am waiting your response for fix that completely.

<script type="text/javascript"></script>

Glad that you are able to fix it.

Thanks

I saw more errors :frowning:

I added code like that,

<script type="text/javascript">
function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];
        if (
            anchor.getAttribute("href") && (
            anchor.getAttribute("rel") == "external" ||
            anchor.getAttribute("rel") == "nofollow" ||
            anchor.getAttribute("rel") == "external nofollow" ||
            anchor.getAttribute("rel") == "nofollow external" )
            )
        anchor.target = "_blank";
    }
}
window.onload = function() {
    externalLinks();
}
</script>

But it displays to who users not log in like that, without row indent, also there is a code break down see to screenshot.

<script type="text/javascript">
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors&#91;i&#93;;
if (
anchor.getAttribute("href") && (
anchor.getAttribute("rel") == "external" ||
anchor.getAttribute("rel") == "nofollow" ||
anchor.getAttribute("rel") == "external nofollow" ||
anchor.getAttribute("rel") == "nofollow external" )
)
anchor.target = "_blank";
}
}
window.onload = function() {
externalLinks();
}
</script>

Hi There,

Let me report this bug to our Dev Team, the issue here is the opening bracket < messing things up.

For now, please write your code like this, and place it on a RAW Content element.

<pre>
function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i&lt;anchors.length; i++) {
        var anchor = anchors[i];
        if (
            anchor.getAttribute("href") && (
            anchor.getAttribute("rel") == "external" ||
            anchor.getAttribute("rel") == "nofollow" ||
            anchor.getAttribute("rel") == "external nofollow" ||
            anchor.getAttribute("rel") == "nofollow external" )
            )
        anchor.target = "_blank";
    }
}
window.onload = function() {
    externalLinks();
}
</pre>

Notice that I wrapped it in <pre> tag, and I change the < with its HTML entity code. But on the front-end the <pre> tag won’t be displayed and the &lt; will be converted to <.

Sorry for the inconvenience.
Hope it helps, Cheers!

I did like you for temporary, I am waiting your news, thank you.

Thank you for understanding, I’ll update this ticket once the issue is resolved. We can not provide an ETA though.

Have a nice day,

Guys I waste my many times while researching a plugin for fix my problem but this types plugins use extra js and css so it makes slow my website. If I use a plugin I also have to use one more plugin for code escape,encoding or I have to encode manuel bla bla. Just problem is X_code shortcode will keep this “<” same on editor and post automatically. Please tell me a function or code change on pro theme. I am trying to fix that for three days. Also I changed all my code snippets on my website to X_code, if I use plugin I have to waste my time for change all posts. Also I disabled visual editor because it makes problem while switching to html editor on some codes. It cant be very difficult for you, intersest me please.

There are many functions for you can reference it. For examle https://wordpress.org/plugins/code-markup/ or https://tr.wordpress.org/plugins/smart-code-escape/

Please guys :sweat:

Hi There,

Again we are sorry for the inconvenience. I have check the report and I can see the developers are able to confirm the bug, unfortunately there is no update yet. We do understand your situation but please bear with us and use the previous alternative at the moment. Thank you.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.