Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6108463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:17:56+00:00 2026-05-23T14:17:56+00:00

I am trying to do a find and replace throughout an entire page, and

  • 0

I am trying to do a find and replace throughout an entire page, and add some parameters to any URLs that contain some specified text. (i am speaking about hardcoded inline a href URLs)

So for example, I want to replace any instances of this:

<a href ="http://localhost/wordpress/">Link</a>

With

<a href ="http://localhost/wordpress/?demo_mobile_site">Link</a>

I tried some replace function I found, but I cant get it to work with the forward slashes in the string.

Any help on this would be appreciated. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:17:57+00:00Added an answer on May 23, 2026 at 2:17 pm

    You don’t need t replace anything just simple add onto a string.

    $('a').each(function(){
        var _href = $(this).attr('href');
        $(this).attr('href', _href + (_href.charAt(_href.length-1) == '/' ?  "? demo_mobile_site" : "/?demo_mobile_site");
    });

    or if you just want to replace the one href you can do something like this:

    $('a[href^="http://localhost/wordpress"]').each(function(){
        var _href = $(this).attr('href');
        $(this).attr('href', (_href.charAt(_href.length-1) == '/' ? _href + "?demo_mobile_site" : "/?demo_mobile_site");
    });

    This including url’s with query strings:

    $('a').each(function(){
        var _href = $(this).attr('href');
    
        if ( _href.indexOf('?') >= 0 ){
            $(this).attr('href', _href + "&demo_mobile_site=");
        } else if ( _href.charAt(_href.length-1) == '/' ) {
            $(this).attr('href', _href + "?demo_mobile_site");
        } else {
            $(this).attr('href', _href + "/?demo_mobile_site");
        }
    });
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find every instance of @username in comment text and replace it
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
I'm trying to find and replace all instances of 'this phrase' with 'that phrase'
I'm trying to find some certain blocks in my data file and replace something
I'm trying to find a way to replace a node with one that has
I'm trying to find a block of text and replace it with a modified
I am trying to do a simple find/replace on all text files in a
In Excel I am trying to use Find and Replace on some data to
I'm trying to create a Find/Replace thing for my text area. I got the
I'm trying to find a regular expression that would allow me replace the SRC

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.