4

Currently I'm having some issues on my website where I made a noob mistake starting out and now it's becoming large and I am still using the out dated system I had in place when starting.

Basically, my website is using WordPress and my download links are stored within the_content portion on my site instead of in some form of custom meta, the worst part is they're not completely uniform only semi uniform which is where I'm having issues. (I've searched most of stack, and other websites now for a source to fix my issue, and no luck)

Here's some of my code.

СКАЧАТЬ: 320 | 320 | 320 | iTunes | iTunes | iTunes
СКАЧАТЬ: CDQ | CDQ | CDQ | iTunes | iTunes | iTunes

Above is what's usually displayed in the_content portion on my website, it's always lead with СКАЧАТЬ: and followed by at least one link.

I need to replace this entire portion with <a href='download.php'>download</a> the rest is already coded, however my JavaScript knowledge is lacking.

EDIT: Not sure what you meant by update expected output code but here you go.

I want to have the content after СКАЧАТЬ: on my website replaced from the following, with the following.

Current:

<p style="text-align: center;"><strong>СКАЧАТЬ:</strong> <strong><a href="http://example.com">CDQ</a> | <a href="http://example.com">CDQ</a> | CDQ | <a href="http://example.com">iTunes</a> | <a href="http://example.com">iTunes</a> | iTunes</strong></p>

Maybe important, it's always wrapped around with a <p style="text-align: center;"> </p> tag also!

Expected:

<a href='download.php'>download</a>
6
  • what exactly you want to replace? Commented Nov 3, 2017 at 5:41
  • 1
    @Prajwal I'm not exactly sure, but I think he's wanting to replace everything that comes after the СКАЧАТЬ: none the less, this sounds like a giant mess. Commented Nov 3, 2017 at 5:42
  • what should be the output? Commented Nov 3, 2017 at 5:42
  • @gurvinder372 I am trying to replace everything after the СКАЧАТЬ: like Placeholder said with the a href I provided in the bottom portion. Sorry I wasn't more direct, i'm genuinely not sure how to solve this issue other then it needs to be done in Javascript. Commented Nov 3, 2017 at 5:44
  • @Herbo please update the expected output code in the question itself. Commented Nov 3, 2017 at 5:45

2 Answers 2

1

If You wants output like this then this will help you else say what you want changes in this,

(function(){
        $('p.download-link a').fadeOut(function(){
            $(this).html('<a href="download.php">download</a>').fadeIn();
        });
    
        
})();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p style="text-align: center;" class="download-link"><strong>СКАЧАТЬ:</strong> <strong><a href="http://example.com">CDQ</a> | <a href="http://example.com">CDQ</a> | CDQ | <a href="http://example.com">iTunes</a> | <a href="http://example.com">iTunes</a> | iTunes</strong></p>

Hope this snippet will help you.

Sign up to request clarification or add additional context in comments.

2 Comments

please check I updated the answer, now it's working with the class name.
please check once again I added a class to your "<p>" tag. if you can add class to your <p> then it will be easily work for you.
0

It seems to me like Javascript would be one way to approach this issue, but ultimately it would be ideal to have the content fixed in the database.

Have you thought about just trying to do a MySQL find/replace to fix the issue?

I have had a lot of luck using the Interconnect It PHP tool before. It comes highly recommended by many sources.

While you should definitely backup your database before doing a find/replace with any tool, part of the advantage of the Interconnect It tool is that it has a dry run feature you can run to see what would happen with your find/replace before actually making the changes in the database.

In this case I would try:

Replace

<p style="text-align: center;"><strong>СКАЧАТЬ:</strong> <strong><a href="http://example.com">CDQ</a> | <a href="http://example.com">CDQ</a> | CDQ | <a href="http://example.com">iTunes</a> | <a href="http://example.com">iTunes</a> | iTunes</strong></p>

With

<p class="download_link_class"><a href="download.php">download</a></p>

I'm guessing you will want to keep a paragraph tag around the replaced text and you may want to add a class to this new paragraph tag as well in case you want to style it differently... replace download_link_class above with your desired class name or just remove the class="" attribute entirely if you don't want it.

Again, make sure you back up the database before running this tool! If you have a separate (staging/dev) environment you can run this tool on first to actually see the results on a non-live site that would be ideal.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.