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 9230745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:53:52+00:00 2026-06-18T05:53:52+00:00

I have a site based on wordpress and I want to change the header

  • 0

I have a site based on wordpress and I want to change the header image for every single post. As every post has its own ‘id’, I want to make a jquery function which would read the post ‘id’ (for example id=”post-8″) and would set a background image named the same way, so I just have to make a new image and upload it everytime I write a new post, and no css changes would be needed.

I have very bare idea of jquery, but my bro’s help I got the following code:

var txt1 = "post-";
        for (var i=0; i<1000; i++){
        var elementId = txt1.concat(i);
        var postimg1 = "url(../images/";
        var postimg2 = ".jpg)";
        var postimgfull = postimg1 + elementId + postimg2;
        var element =  $("#" + elementId);
        if (element != null) {
            $(".posthead").css('background-image', postimgfull);
        }else {
            break;
        }

But using that I don’t get the image named “post-8.jpg”, what I get is an image named “post-999.jpg”.

Can you help me here?

Thankyou mates!

  • 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-06-18T05:53:53+00:00Added an answer on June 18, 2026 at 5:53 am

    I guess everything goes fine in your code except there should be

    element.css('background-image', postimgfull);

    in stead of

    $(".posthead").css('background-image', postimgfull);

    and it should be good to go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My site needs to have image based posts, meaning the post is only an
I have a wordpress based site, that has data divided in it on the
At the moment, I have a wordpress-based site at http://sub.mydomain.com , running for 2
I'm creating a customized WordPress theme based on an existing site. I want to
I have a wordpress based site where for widgets have titles like Browse By
I have to create a wordpress based site for programming articles, blogs, videos etc.
I have a wordpress based classifieds site, i am trying to create and xml
I have a lightweight online shopping site based on JSP and XML, and I'm
I have a site where I am trying to implement a jQuery UI based
I am creating a very large PHP MVC-based site that will have a large

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.