javascript error being indexed - php

I have a webpage. On it there is a javascript warning to the users who have javascript disabled. This is in the body part of the html page, towards the top. In google this is what shows in the description!
How can I make this go to the bottom of the page to stop google using it as the descriptiuon?
It is in a class if that helps...

If you move the warning to the bottom of the code you can use absolute positioning (or fixed if you want it to scroll with the page) to have it display at the top of the page. This way it is not the first text that Google sees when it indexes the page. Along with that I would add in the meta description tag as Christopher McCann said.

Have you set a meta description tag? Do you have other content on the page?
You can't MAKE google choose what it displays as the description but it will usually use the meta description tag so make sure you have one set. It won't fix straight away - you will need to wait until Google re-crawls your website.

Related

Modify the footer of each post PHPBB?

I want to add the ShareThis buttons for every topic on my forum. I have already modified the overall header and added the code to the head tag.
How can i modify the templates so they appear for each topic? Also is there anyway to add them to the footer of or under each topics first post rather than besides the title?
I am using PHPBB 3.1.10
Many thanks
I don't know which code fragment you are trying to inject, but I assume you have already included a link to a javascript script in your header (you can also include it in your footer instead) and now you need to add the html element of the button that triggers this script.
If you want to show something only in the topics page, then you should change the styles/your_style/template/viewtopic_body.html file. You can choose where to insert it and, depending on your style and the place, you may need to do some small modifications (e.g. using the inline style="" attribute).
If you want to show it on the footer of each post, you can try putting your element just before or after the line <!-- EVENT viewtopic_body_postrow_post_after --> in your viewtopic_body.html file. The events are like "interesting points" in the styles and you can see a list of them here.
In any case, make sure that you don't make any syntax errors (and always keep a backup). You can validate your page using the W3C validator.

Don't have access to head - Need to Add Meta OG Tags by either JQuery/PHP

I know this method isn't ideal, but I have no alternative. I can't access the head, and I need to add OG tags to a page. I tried simply embedding them into the page on the off-chance that it might work, but I only received a warning about the error in the Facebook Debugger.
I tried to add them to the head by javascript, but that all works on the surface since that appears after the page has loaded....I assume PHP would be the only practical way to add in the og:title, og:image, and og:description I need.
Does anyone know if/how it is possible to add the meta tags to the head so that Facebook will detect them? Again, I know this isn't the best way to go about it, but I only have access to the body content. Greatly appreciate any help!
The Facebook bot does not call JavaScript, so the Open Graph Tags can´t be added with JavaScript. Your need to add them in your PHP code, but you can´t do that AFTER page load - that´s not how PHP works.
Also, use the debugger to check if the Open Graph Tags are correct: https://developers.facebook.com/tools/debug/

Is there a way to maintain the scrollbar position On a page refresh (Without Javascript)?

I am building a system where users can edit content inline, however a requirement of the project is:
No Javascript!
Is there a way using just php, html and css to maintain the scrollbar position on a page refresh so when an edit button is clicked the page doesn't jump up to the top?
any suggestions?
This sounds like the perfect place for progressive enhancement. If there is no javascript, then use the named anchor tag (as Olli mentions) and a hash on the URL to get it close (but it won't be exact).
If there is javascript, then save the scroll position to a cookie or URL parameter and restore the scroll position exactly when the page reloads.
There should be no harm in offering the best experience you can without javascript, but offering a better one when javascript is available (progressive enhancement).
Another possibility is to use a paged or tabbed interface (to position the edit field near the top of the window) so it's a lot less likely that there is any scrolling when the field is edited.
Do it so:
<a name="jumphere"></a>
and when you have edited
http://yourUrlHere.com/somepage.php#jumphere

How do I push website content down and insert ad at the top?

Can someone tell me how to write code that pushes the content of a finished webpage down half an inch or so, then loads an ad across the top of the page, like this example:
http://abcnews.go.com/International/hideouts-sacred-spaces-experts-baffled-mysterious-underground-chambers/story?id=14136379
(example may no longer be showing this ad/function)
The entire page loads, then gets pushed down, then the ad loads at the top of the page. My code for this would be at/near the bottom of my clients html.
The ad content will come from a different server.
The same code would ideally work with all/most finished websites instead of being specifically tailored for each one.
Thanks for any and all help.
I suppose you implement your ads in your HTML by using a static code (eg. when you're using Google Ads). When you put this code on top of your page, it'll show the ad on top of your page. Optionally, you can style it a bit so it's centered.
Since you load your ads from a different server, I don't see any reason why the HTML-code behind those ads is dynamic (I don't know if it is?). Your ad-provider will take care of showing the ads in a random-order.
If you'd looked at the source of the page you'd see this this is achieved using JavaScript, not PHP. If you want it to happen (seemingly) after the page loads you need to write some php to inculde the html/JavaScript/images whatever for the ad, then some JavaScript to dispay it once the page has finished loading. Or use AJAX to dynamically modify the DOM.
Check out the jQuery JavaScript framework.
I would prefer to use a front-end code like jquery or normal javascript, and prepend your ad to the body.
OR
If you want to do it with a server-side language. You can add the server variable just after the opening body tag, and populate the html to the variable via server-side code.
See my example:
Gray : body tag
Green : your website
Red : the ad section
If you don't have a wrapper container around your div, add one. And use the methods I mentioned above to prepend the ad to your site.

Javascript find and scroll to text

I need a bit of Javascript that will find some text in the html page and then scroll to that point.
So something like "Are you a Lib Dem or Tory supporter and how do you feel about the deal?" would scroll down to the bottom of the page for this bbc news page: http://news.bbc.co.uk/1/hi/uk_politics/election_2010/8676607.stm
Im hoping there is a built in function for both the find text and scroll.
Try this. It works on the site you provided:
$(window).scrollTop($("*:contains('Are you a Lib Dem or Tory'):last").offset().top);
It finds last, deepest element that contains given phrase on the page and scrolls to it.
If you want to do the same thing without jQuery you need to use XPath becasue CSS didn't get contains() selector.
window.scrollBy(0, document.evaluate("//*[text()[contains(., 'Lib Dem')]][last()]", document.body).iterateNext().getBoundingClientRect().top);
If you need to scroll to the first occurrece, not the last one, delete [last()] from this code.
You can also use what google is using to scroll to and highlight specific portions of a search result when you visit the page.
It generates a URL like this:
https://www.inc.com/peter-roesler/heres-what-googles-new-highlight-feature-means-for-your-website.html#:~:text=If%20you%20see%20a%20featured,saw%20in%20the%20featured%20snippet.
It is kind of nifty. The syntax seems to be:
https://example.com/#:~:beginning_of_text,end_of_text
See the following blog post for a few more details:
https://web.dev/text-fragments/
It is supported by version 80 and beyond chromium based browsers. So, limited support right now, but depending on your use case, it could be useful.

Categories