Jump to content


Photo
- - - - -

How to put a piece of code into the body section?

code body

Best Answer Danny , 11 October 2013 - 10:45 AM

Thats fine and no problem. However, they're the creators of the code, so they will know best. I can only check how you have implemented the code, I can't check whether the code is right or not as I have no idea what it's supposed to do.

Go to the full post


  • Please log in to reply
24 replies to this topic

#1 lutz

lutz

    Advanced Member

  • Members
  • 92 posts

Posted 09 October 2013 - 03:13 PM

Hi there!

 

I have to put this piece of code into the body section of the site to deliver the ads correctly:

 

<script type=“text/javascript“>
window.onload = checkWallpaper;
</script>
 
 
The function "checkWallpaper" is stored in the header section, but the code above has to be put into the body section. But I have no idea how to do that. I already tried it in the functions.php file of Pagelines customize folder, but that didn't work.
 
Can please someone tell me in which file I have to copy this code? So that it won't be overwritten with every update of Pagelines?
 
Thanks in advance!


#2 Jake

Jake

    Advocate

  • Premium
  • 565 posts
  • LocationNC, USA
  • Country: Country Flag

Posted 09 October 2013 - 03:29 PM

Hi @

Please Login or Register to see this Hidden Content

- I think your best bet is probably to add it to the the custom script section in the DMS visual editor. Navigate to Custom Code - Custom Scripts.



#3 lutz

lutz

    Advanced Member

  • Members
  • 92 posts

Posted 09 October 2013 - 03:53 PM

Sorry, I guess I'm in the wrong forum! I use the Pagelines Theme – you're talking about DMS, that's something different, right?



#4 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 09 October 2013 - 04:11 PM

I'm moving the topic to the correct product.



#5 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 09 October 2013 - 04:18 PM

Lutz, your question is a bit vague, but I suspect that you're trying to add that code to implement advertising in the site.  What we need to know is, where in the site do you want to place it? In posts, pages, everywhere, sidebars, or someplace else?

 

In Framework, I can tell you that javascript will not work in the Morefoot, and since you mentioned the body (which is the whole site from header to footer), we're unclear.  Just adding that code to the pagelines-customize/functions.php will do nothing without a hook, telling it where it's supposed to function, and disabling PHP so the code doesn't interrupt it, then re-enabling PHP after the script is finished.

 

Are you familiar with hooks?



#6 lutz

lutz

    Advanced Member

  • Members
  • 92 posts

Posted 09 October 2013 - 04:49 PM

@

Please Login or Register to see this Hidden Content

thanks for that!

Alright, here's the whole story ;))

 

To add advertising on all pages, posts, everywhere, the site is mobiwatch.de

Problem: There are different types of ads; sometimes the Leadboard has to be moved to the right and the Skyscraper up to form a so called Hockeystick. In other cases the Leaderboard has to go over the Skyscraper ... and sometimes they have to work as separated ads.

 

To do so, I have got some pieces of code to implement it into my site, they look like this:

 

<html>
<head>
<title></title>
<script type="text/javascript">
function checkWallpaper() {
if (typeof(adtype) != 'undefined') {
if (adtype == 'wallpaper') {
/* move Skyscraper up and Leaderboard to the right */
#site #sidebar2{margin-top:-464px;}
 #site .section-sb_universal {position:relative; top:0px; left:250px;} 
}
if (adtype == 'expwallpaper') {
/* move Sky up and below the Leaderboard, making the Leaderboard top the Sky */
#site #sidebar2{margin-top:-374px;}
 #site .section-sb_universal {position:relative; top:0px; left:410px;} 
}
}
</script>
</head>
 
I can simply put that code in the "Site Options - Custom Code - Headser Scripts" section. So far, so good.
 
But here it comes:
I have been told to put this code into the body section of my site:
 
<body>
<script type=“text/javascript“>
window.onload = checkWallpaper;
</script>
</body>
 
And I only know the functions.php and style.css files in my pagelines-customize folder (in wp-content / plugins).
So I have no clue how to call that fuction "checkWallpaper", meaning in what file in which folder do I have to copy this code?
Please remember: I almost knowing nothing about HTML, just trying to get my site work and now trying to add some advertises!
 
Thanks again in advance!
 


#7 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 09 October 2013 - 10:40 PM

I have ads in my Framework site too, and simply apply a class to them so that I may position each as desired. To achieve the ads in the header, I used a hook.  To place the ads in a sidebar, I used text widgets, which accept Javascript.

 

You're adding the code above and applying the CSS inline, which makes it fixed and thus ruins your mobile view.

 

Even in your header, you could use a Universal Sidebar in place of code added into the head tags.

You could go to Drag & Drop, and include the Universal Sidebar above the branding area.  Then, in Dashboard > Appearance > Widgets drag a text widget to the Universal Sidebar, and paste your ad code in there. Instead of using inline CSS, like 

 
/* move Sky up and below the Leaderboard, making the Leaderboard top the Sky */
#site #sidebar2{margin-top:-374px;}

 #site .section-sb_universal {position:relative; top:0px; left:410px;}

You can just wrap the entire javascript code in something like <div class="leaderboard1"> THE JAVASCRIPT CODE</div>

 

Then, you just apply the .leaderboard1 to the CSS and paste it to the Custom Code area.

 

This is a much more efficient, and proper way to achieve this.



#8 lutz

lutz

    Advanced Member

  • Members
  • 92 posts

Posted 10 October 2013 - 10:53 AM

@

Please Login or Register to see this Hidden Content

,

 

thanks a lot!

I already use the universal sidebar for the Leaderboard as you told me to ...  ;))

And the Skyscraper is indeed a text widget in the secondary sidebar.

 

But to be honest, everything you wrote after the quote I don't know how to do.

I mean: Where do I have to put the "<div class="leaderboard1"> THE JAVASCRIPT CODE</div>" thing?

Into the style.css file of the pageline-customize folder? Or where?

 

Same with the " .leaderboard1": You wrote "Custom Code area" – you mean in "Pagelines – SIte Options – Custom Code – CSS Rules"?

Or where do I have to put that?

 

And as far as I understand all that (which is not very far) there's still the question open, where I have to put this code:

<body>

<script type=“text/javascript“>
window.onload = checkWallpaper;
</script>
</body>
 

Or is this last thing not needed when I'm going the way you're describing?

 

Sorry for bothering you, I'm no programmer at all, just trying to run my website somehow – but advertising is a very important topic, I have to make that run somehow ...



#9 Danny

Danny

    Is Awesome!

  • Moderators
  • 16289 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 10 October 2013 - 12:00 PM

All custom Javascript should go in Wordpress Admin Dashboard > PageLines > Site Options > Custom Code > Header.



#10 lutz

lutz

    Advanced Member

  • Members
  • 92 posts

Posted 10 October 2013 - 12:48 PM

@

Please Login or Register to see this Hidden Content

 

thanks!

 

This concerns to the  "<div class="leaderboard1"> THE JAVASCRIPT CODE</div>" , right?

 

But what about the " .leaderboard1" thing? Where dies that belong?

 

And where do I have to put this code or is is no longer needed?

<body>

<script type=“text/javascript“>
window.onload = checkWallpaper;
</script>
</body>


#11 lutz

lutz

    Advanced Member

  • Members
  • 92 posts

Posted 10 October 2013 - 12:53 PM

@

Please Login or Register to see this Hidden Content

 

oh, and by the way: Do I need "<script type="

Please Login or Register to see this Hidden Content

">" when I'm using "div class"?

I now have the following code stored in the custom code section you mentioned:

 

<div class="

Please Login or Register to see this Hidden Content

">
<script type="

Please Login or Register to see this Hidden Content

">
function checkWallpaper() {
if (typeof(adtype) != 'undefined') {
if (adtype == 'wallpaper') {
/* move Skyscraper up and Leaderboard to the right */
#site #sidebar2{margin-top:-464px;}
#site .section-sb_universal {position:relative; top:0px; left:250px;}
}
if (adtype == 'expwallpaper') {
/* move Sky up and below the Leaderboard, making the Leaderboard top the Sky */
#site #sidebar2{margin-top:-374px;}
#site .section-sb_universal {position:relative; top:0px; left:410px;}
}
}</script> </div>

 

Is that correct?

Because nothing happens ...  ;))



#12 Danny

Danny

    Is Awesome!

  • Moderators
  • 16289 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 10 October 2013 - 01:04 PM

Your checkwallpaper script will need to be placed in Wordpress Admin Dashboard > PageLines > Site Options > Custom Code > Header Scripts, which from the sounds of it, you've already done this.

 

As for the rest of your, I assume this is to load your ads, so this code needs to placed in specific areas of your page. If this is correct, you will need to use a hook. See here for more information - 

Please Login or Register to see this Hidden Content



#13 lutz

lutz

    Advanced Member

  • Members
  • 92 posts

Posted 10 October 2013 - 01:21 PM

@

Please Login or Register to see this Hidden Content

 

thanks again!

 

So I put this code into the functions.php of my pagelines-customize folder:

 

add_action('window.onload', 'checkWallpaper');  

 

Is that correct?



#14 lutz

lutz

    Advanced Member

  • Members
  • 92 posts

Posted 10 October 2013 - 01:24 PM

I mean: what is the correct action_name to put the code

    window.onload = checkWallpaper;

into the body section?

I don't have more info that this ...



#15 Danny

Danny

    Is Awesome!

  • Moderators
  • 16289 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 10 October 2013 - 02:08 PM

When you say body section what do you actually mean? Does the scripts instructions state it needs to be added right after the open body tag or does this code need to be placed wherever you wish to have an add ?

Do you have a link to the instructions for this code ?



#16 lutz

lutz

    Advanced Member

  • Members
  • 92 posts

Posted 10 October 2013 - 02:14 PM

@

Please Login or Register to see this Hidden Content

 

like I wrote above, the instructions tell that I have to get this into the header section:

 

<html>
<head>
<title></title>
<script type="text/javascript">
function checkWallpaper() {
if (typeof(adtype) != 'undefined') {
if (adtype == 'wallpaper') {
/* move Skyscraper up and Leaderboard to the right */
#site #sidebar2{margin-top:-464px;}
 #site .section-sb_universal {position:relative; top:0px; left:250px;} 
}
if (adtype == 'expwallpaper') {
/* move Sky up and below the Leaderboard, making the Leaderboard top the Sky */
#site #sidebar2{margin-top:-374px;}
 #site .section-sb_universal {position:relative; top:0px; left:410px;} 
}
}
</script>
</head>
 
 
And this code has to be placed in the body section – without saying where exactly:
<body>
<script type=“text/javascript“>
window.onload = checkWallpaper;
</script>
</body>
 
So I'm trying to figure out how to do that in Pagelines ;))


#17 Danny

Danny

    Is Awesome!

  • Moderators
  • 16289 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 10 October 2013 - 03:15 PM

OK, so the code that needs adding to the body area, just add it via a hook.

 

You can find the correct hook location using either hooker or action map. You can download Action Map from here - 

Please Login or Register to see this Hidden Content

 

You can find out more about hooks here - 

Please Login or Register to see this Hidden Content

 

You could try this (untested):

 

Please Login or Register to see this Hidden Content


  • Jake likes this

#18 lutz

lutz

    Advanced Member

  • Members
  • 92 posts

Posted 10 October 2013 - 03:49 PM

@

Please Login or Register to see this Hidden Content

 

thanks a lot !!!

 

I can't tell if it's correct because nothing changed – but that might be a reason of the code in the header.

Did you check the syntax and everything?

Is this okay for you:

 

<div class="

Please Login or Register to see this Hidden Content

">
<script type="

Please Login or Register to see this Hidden Content

">
function checkWallpaper() {
if (typeof(adtype) != 'undefined') {
if (adtype == 'wallpaper') {
/* move Skyscraper up and Leaderboard to the right */
#site #sidebar2{margin-top:-464px;}
#site .section-sb_universal {position:relative; top:0px; left:250px;}
}
if (adtype == 'expwallpaper') {
/* move Sky up and below the Leaderboard, making the Leaderboard top the Sky */
#site #sidebar2{margin-top:-374px;}
#site .section-sb_universal {position:relative; top:0px; left:410px;}
}
}</script> </div>

 

 

Well, I had a look at the source code, here I find now this part:

 

<!-- Start >> HTML Body -->
<body class="

Please Login or Register to see this Hidden Content

">

<script type="

Please Login or Register to see this Hidden Content

>
window.onload = checkWallpaper;
</script>
<div id="

Please Login or Register to see this Hidden Content

" class="

Please Login or Register to see this Hidden Content

">
    <div id="

Please Login or Register to see this Hidden Content

" class="

Please Login or Register to see this Hidden Content

">
                <div class="

Please Login or Register to see this Hidden Content

">
                        <header id="

Please Login or Register to see this Hidden Content

" class="

Please Login or Register to see this Hidden Content

">
                <div class="

Please Login or Register to see this Hidden Content

">
                    

<!-- Universal Sidebar | Section Template -->

 

This seems to bo alright, don't you think so?

 

Or did you find anything I should change?



#19 Danny

Danny

    Is Awesome!

  • Moderators
  • 16289 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 11 October 2013 - 09:22 AM

Hi, The best thing to do would be to ask this question on the site where you received the code from. As far as I can tell it looks fine, but that doesn't mean it is. The developer/author of the code is the best person to ask.

#20 lutz

lutz

    Advanced Member

  • Members
  • 92 posts

Posted 11 October 2013 - 10:37 AM

@

Please Login or Register to see this Hidden Content

,

 

sure, did already – but I don't know the people in that company and their state of knowledge concerning WordPress and especially Pagelines – so I asked you, too to check it. Just to be sure!

Thanks again for everything!!!