Adding DFP Script to Wordpress - wordpress

I am playing with Wordpress 3 for the first time and had a quick question.
I am placing ads on a site and wondered the best practice to add in the script. The code that Google generates is in 2 parts, one for the of the page and one where the ad should go
The head code is in the form
<script type='text/javascript' src='http://partner.googleadservices.com/gampad/google_service.js'>
</script>
<script type='text/javascript'>
GS_googleAddAdSenseService("ca-pub-123123");
GS_googleEnableAllServices();
</script>
<script type='text/javascript'>
GA_googleAddSlot("ca-pub-123123", "300x250_Ad");
</script>
<script type='text/javascript'>
GA_googleFetchAds();
</script>
Then the code for the ad is:
<!-- ca-pub-123123/300x250_Ad -->
<script type='text/javascript'>
GA_googleFillSlot("300x250_A");
</script>
I downloaded a plugin Advertising Manager that allows me to add ads into the page but only seems to allow putting in one block of code. I can add all the code joined up but if I want to add other ad positions later it is not the best...
I can't go into my Theme and add the code in there, as I am using Multiple Sites the code will need to difer from site to site, is there something very simple I am missing to add stuff into the and then I can use Advertising Manager to display the individual ad code...

Try using the the AdSense-Deluxe WordPress Plugin

It would appear the plugin has a bug, the shortcode you're using is calling a function which is directly outputting the code for DFP (which is called when wordpress is preparing the page content, hence it appearing all at once at the top) instead of returning it to be inserted throughout the content.

Related

MathJax on a WordPress free blog

I have a free WordPress blog with a URL like e.g.
https://blog.wordpress.com
I mean I don't have my own domain, only a WP sub-domain.
I noticed that there's a MathJax plugin in WP, but I cannot enable it unless I have a business plan.
So... is there any other way to have MathJax enabled in my blog? With my free account I don't find any way to add some JavaScript tags to the header or to the template of my blog or to anything similar (you see... I would like to have MathJax enabled on all the posts I create).
Is this possible at all with a free WordPress blog like mine?
All I want is to place e.g. these two tags (somewhere... but where?!?!) and get my math working:
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
Is this possible at all?
MathJax v3 works on blogspot with:
<script async id="MathJax-script" src="https://cdn.jsdelivr.net/npm/mathjax#3/es5/tex-chtml.js"></script>
It can work on WP as well.

Can I add my existing html homepage google analytics code into new wordpress homepage?

We are having a html website whose homepage and other few pages has google analytics code and keywords. Now we have created a new homepage on wordpress which will be our future homepage. So my question is can I use my existing homepage GA code into my new wordpress homepage? If yes then how? We don't want to lose our previous tracking data at any cost.
How can use it? Please Help.
TIA.
Yes, you can use your existing google analytics code by using WordPress plugins.
There are many plugins in WordPress which provides ability to integrate your google analytics code to your site and all pages dynamically and also display you a complete tracking reports as well.
here is one plugin link for your reference please check it.
https://wordpress.org/plugins/googleanalytics/
There are lot's of other plugins as well you can simply check out in WordPress plugins repository.
=> Also you can add your google analytics code programmatic as well.
Please copy below code and paste it into your activated themes functions.php file at the end of the file.
function add_google_analytics_code_to_pages(){
?>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-ADD YOU GOOGLE ANALYTICS ID HERE', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
<?php
}
add_action("wp_head","add_google_analytics_code_to_pages");
Just add your google analytics tracking id into about script.
Replace your tracking id instead of this code.
'UA-ADD YOU GOOGLE ANALYTICS ID HERE'
Unless I am missing something here, sure!
All you have to do is enter your Google Tracking code inside the <head> tags, within the header.php template file. Ideally, just before the closing </head> tag.
By inserting your Google Tracking code, within the header.php template file, every WordPress page will be tracked.
Your header.php template file will typically be found within the following directory path:
wp-content > themes > theme-name
If you are not the theme author, don't forget to create a Child Theme. You will then need to insert the appropriate header.php template file within said Child Theme.
Google Tag Assistance:
For the most part, the above should resolve your problem. You can check whether the Tracking code has been correctly installed by:
Reviewing the code within the Source Code
Installing Google Tag Assistance within Chrome
Exception:
Again, the above should be enough to resolve your issue. Some themes however, do create different headers, for different pages of the site. For example: An eCommerce site may want a different header on their shop pages to their Blog Pages. To achieve this, header template files, such as below would be created:
header-shop.php
header-blog.php
header-ppc.php
To then 'call' each header, the following example PHP entry would be placed within the relevant template file(s):
<?php get_header( 'shop' ); ?>
'shop' being whatever word appends the header- file name. In this case, 'shop', 'blog' and 'ppc'.
You do not need to worry much about this. All you need to do, is head into the root of your theme as follows:
wp-content > themes > theme-name
Look for any files with begin with header- and ensure they contain the Google Tracking code.
In the event you are using a Child Theme, simply copy the header- files over to the root of your Child Theme first and then modify accordingly.
Hope this helps.

inserting google advertisements with html

Good day,
I'm sorry if this might be a duplicate question but most of the questions speak of Google AdSense and I've never used that.
Getting to the point, I would like to know if anyone knows how to add an advertisement from Google to an HTML 5 site.
I am doing a project. The actual site files will be on the local drive, but I would like to i.e. insert an on my page that would draw some random Google Ads and place them in this section.
I do not wish to create an advert or anything of the sort. Let's say that I have the section at a 600px by 100px block, I would like to have that "draw" any ads of a certain category to be placed there at run time.
Like I said the page itself will be local, but using internet access the page should fetch these ads.
Thank you in advance for a speedy reply, and I would like to apologize if I over explained.
It is very easy to insert the Google Adsense in HTML just paste your code inside the body tag and use bootstrap or CSS3 for the positioning.
<html>
<head>
This is the head of your page
<title>Example HTML page</title>
</head>
<body>
**Paste your google adsense code inside the body**
This is the body of your page.
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Homepage Leaderboard -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1234567890123456"
data-ad-slot="1234567890"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</body>
</html>
Refer Get and copy the ad code (click "If you haven't yet created an ad unit under "How to get and copy your ad code")
Then refer Where to paste the ad code in your HTML
It's explained pretty well
<html>
<head>
This is the head of your page
<title>Example HTML page</title>
</head>
<body>
This is the body of your page.
<!-- Ad block -->
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1234567890123456"
data-ad-slot="1234567890"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<!-- End of Ad block -->
</body>
</html>
Adsense can not be loaded from localhost or from a saved html file. It will not work.
Google checks if the domain is accepted into adsense before showing an ad.
So when you load an ad from local, domain property will be missing.

Change wordpress menu href

I wanna change the href of a specific menu item on all pages. Is this possible? Where should I put the code?
I also added this javascript to the end of a specific page:
<script type="text/javascript">
document.getElementById("menu-item-100").href="xyz.php";
</script>
It didn't work even though when I viewed the page source it showed that the script was placed after the original href of the menu.
I don't wanna use custom links.
Try putting this in your footer.php
<script>
jQuery(document).ready(function($) {
$("#menu-item-100").attr("href", new_href);
});
</script>
Wordpress a lot of the times needs to have jQuery(document).ready(function($) for no-conflict reasons.
Try it, may be helpful to you:
$("#menu-item-100").attr("href", new_href);
Apparently the element with the ID of menu-item-100 had an a tag inside of it; so I had to retarget the whole thing.
This fixed the whole thing.
document.getElementById('menu-item-100').getElementsByTagName('a')[0].href="THE LINK";
Thanks to #NooBskie I put it inside the footer.php and it affected all the pages.

Wordpress Image Gallery Using External Images

I would like to know of any known image or video gallery plugins that use external media sources instead of having to upload via wordpress media library.
Worst case, is there a plugin that can performed a scheduled / updates only import from a file server?
Thanks in advance!
You can use the following code jointly with ImageZone.
With ImageZone you can collect external images and share them, while the code will render them into html. The code looks like:
// where do you want to add the gallery
<div id="GalleryId"></div>
<style>...</style>
// this is generated by imagezone
<script type="text/json" id="GalleryId">...</script>
<script type="text/javascript">
function setup(gid){
}
setup("GalleryId");
</script>
and you could make it a wp shortcode

Resources