This should be a standard YouTube video:
This should only be audio of the same video:
This should be a standard YouTube video:
This should only be audio of the same video:
Decided to try out this geolocation code from W3 Collective. It uses Leaflet instead of Google Maps so I don’t need a Google API code. Note that if you are using a VPN, it may not accurately show your location.
Since this can compromise privacy, the position is not available unless the user approves it.
Most themes which offer a header image as one of its options have a common problem: the entire image often does not get displayed, i.e., the header is too short or the sides of the image get cut off, especially as the screen width gets narrowed. The reason behind this is that in most cases, the theme sets the background-image property of a header element to display the image. The problem with that approach is that the header element does not take on the dimensions of the background image like it would if an actual image element (<img>) were used. The theme has to set the dimensions of the header element using CSS, and most of the times, the ratio of the width to height doesn’t match the image’s dimension ratio.
This tutorial is an example of how to get around that limitation using Javascript (more precisely, jQuery). That is, as you resize the width of this particular post, you will see that the header automatically scales so that the entire image is always displayed.
The first thing you need to do is to create a header image that will have the right proportions. It should be as wide as the widest width of your header element. For example, the content (and header) on this site is set to be a maximum of 960px, so I need a header image that is at least 960px wide. If you have a header that spans across the entire width of the browser window, you may want to create a header image that is about 2048px wide. When you create the image, make a note of the dimensions of the image. For example, the dimensions of the image that I am using above is 2048px wide by 810px tall.
Next, you need to figure out which element has the background or background-image property set to display your header image. If you know how to use a web debugging tool like Firebug or Chrome Developer Tools, it should be fairly easy. Sometimes it’s going to have a class called site-header or an ID called masthead, but it just depends upon the theme. You are going to need this piece of information so the script knows what element to change.
The next thing you need to do is add some jQuery/Javascript that will set the event handler for the window resize event. Use a plugin like Header and Footer. The script will look like this:
<script>
var image_width = 2048; // Set this to the width of your image
var image_height = 810; // Set this to the height of your image
var image_ratio = image_width / image_height;
jQuery(document).ready(function($){
// This line sets the header to the correct height once the window is loaded
// In place of #masthead, set the CSS selector used for your theme's header element
$('#masthead').css("height", $('#masthead').width() / image_ratio);
// This section is the event handler for the window resize event.
// When the window is resized, the header height is adjusted.
// In place of #masthead, set the CSS selector used for your theme's header element
$(window).resize(function(){
$('#masthead').css("height", $('#masthead').width() / image_ratio);
});
});
</script>
Note the first two lines of the script is where you will set the dimensions of your image. The script will then calculate the width to height ratio and use it to adjust the height when the window gets resized. Also note that because the header element on my page has an ID of masthead, the script uses the #masthead CSS selector. If the header element for the theme that you are using has a class of site-header, then you would change all instances of #masthead to .site-header.
That’s pretty much it. You may need to add some media queries to adjust the font size of the site title, for example, because your header is going to shrink in height quite a bit at narrow (e.g., cell phone) widths.
I often come across questions from beginning WP developers asking how to create menu items which do not link to a physical page. That is, hovering over the menu item should expand the sub-menu, but clicking on the main menu item should not cause anything to happen, only the sub-menu items should link to another page. The way to do this is to create a custom menu item that links to #. The instructions below assumes that you’ve already created a custom menu.
Continue readingThis is another general WordPress question that I see quite often: how can I create a menu item that displays a page of posts belonging to a particular category? For example, let’s say I have a site about animals, and I’ve created a category called Dogs and a category called Cats, and by clicking on a menu item labeled Dogs, I want to display a list of posts that have the Dogs category assigned to it.
Continue readingAdding Google Analytics to your site is very easy. You first need to get your scripting code from Google Analytics. Your tracking code is going to look something like this:
Continue readingThis post is an example of how to change an image “in place” when the mouse is hovered over different areas.
Continue readingHad a question about how to recreate the fixed borders as seen on this page. It’s not too difficult, all you need to do is first fix the header at the top (and add some Javascript if you want to scale down the menu after the user scrolls down the page), and then add three other empty <div>s to form the left, right, and bottom borders, making them fixed as well. You can either add the empty <div>s using a simple text widget, or add them to one of your main templates.
Continue readingWanted to try out the example code from here.
When you move the mouse over this image, the cursor will turn into a magnifying glass and enlarge the section of the image underneath:
There are a number of standard cursors that are used depending upon where on the web page the mouse is located. The default cursor is the arrow, but if held over a hyperlink, the cursor usually turns into a pointing hand.
The cursor property allows you to use CSS to change the cursor image when the mouse is moved over a particular element. For example, if you hover your mouse over the block below, you’ll see that the cursor changes into a pizza slice:
The CSS to change the cursor to an image looks like this:
.pizza {
cursor: url(/wp-content/uploads/2020/03/42559-e1565325592349.png),auto;
}
The DIV with the red borders was assigned a class of pizza, so the rule comes into play when the mouse moves over it. You want to make sure that the image you’re using has dimensions of 32×32 to insure compatibility across all browsers.
If you want to make the image the default cursor for the page instead of just a certain element, then try using the body element as a selector:
body {
cursor: url(/wp-content/uploads/2020/03/42559-e1565325592349.png),auto;
}
As an example, pick Whole Page from the options below to see how the cursor will change to a pizza slice for the whole page:
If you do change the default cursor for the entire page, then you may want to use an altered image for hyperlinks so your users know if they are positioned over one.