How to Add JavaScript to WordPress Pages and Posts

JavaScript is a programming language that can add interactive features to your website. Learning how to use it on your WordPress site, including specific sections, can help you leverage the code more effectively. 

There are multiple ways to add JavaScript to your WordPress pages and posts. Whether you use a plugin, use functions and hooks, or edit your theme’s files, you can get the customization you want.

In this post, we’ll review what JavaScript is and how you can add custom code to WordPress. We’ll walk you through the process of each method and answer some frequently asked questions. 

Continue reading → How to Add JavaScript to WordPress Pages and Posts

Posted in Code snippets, Learn | Comments Off on How to Add JavaScript to WordPress Pages and Posts
Jetpack CDN controls and customization - coder at laptop

Jetpack Hooks: Control Jetpack CDN

Note: We wrote this article with advanced users in mind; you’ll need some coding knowledge to accomplish these tasks. As always, enable Jetpack Backup so you can easily revert your site in case of a mistake. Hooks are a way for one piece of code to interact with or modify another piece of code. They make up the foundation for how Jetpack interacts with WordPress Core.

If you have questions about how to use these yourself, ask the Jetpack community in the forums. If you’d like to hire help, reach out to a service like Codeable

Continue reading → Jetpack Hooks: Control Jetpack CDN

Posted in Code snippets, Performance | Tagged , , , , , | 10 Comments

Hook of the Month: Customize Related Posts

Jetpack’s Related Posts module is a simple and easy way to add contextual posts your visitors might be interested in when they reach the end of a post on your website. To use this feature, go to your site’s Jetpack settings and enable the module. All the magic happens behind the scenes, on the WordPress.com cloud: Jetpack’s natural language search engine scans all of your posts, analyzes all their content based on several factors, and returns a list of related posts for each one of your posts.

Now that Jetpack has worked its magic1, let’s discover how to customize those related posts or how to customize their display on your site.

Related Cats

Use filters to customize how Related Posts are displayed on your site

Posted in Code snippets, Tips & Tricks | Tagged , , , , | 4 Comments

Announcing: developer.jetpack.com

Do you use hooks to customize Jetpack’s default behaviour? Are you a fan of our Hook of the Month series? Then you’ll love our new code reference!

Jetpack for developers

Continue reading → Announcing: developer.jetpack.com

Posted in Code snippets, Tips & Tricks | Tagged , , | Comments Off on Announcing: developer.jetpack.com

Hook of the Month: Customize Modules, Shortcodes, and Widgets

Whether you’re a blogger, a business owner, or a developer – Jetpack comes with many different features you can use to build your site, write your posts, and promote them. However, you may not use all of these features. This month, we’ll discover how to use filters to customize the list of features added by Jetpack.

Photo: Andrewfhart / Flickr

Photo: Andrewfhart / Flickr

Use filters to customize the Jetpack features available on your site

Posted in Code snippets, Tips & Tricks | Tagged , , , , , | 1 Comment

Hook of the Month: Customizing Sharing Buttons

Jetpack’s sharing buttons look good, are simple to use, and include several hooks allowing you to customize every single aspect of the module. Let’s learn to use some of these hooks together!

Use filters to customize sharing buttons on your site

Posted in Code snippets, Tips & Tricks | Tagged , , , , | 11 Comments

Hook of the Month: Customizing Contact Forms

Did you know you could create contact forms with Jetpack? This month, we’ll discover different ways to customize these forms on your site.

Use filters to customize Contact Forms on your site

Posted in Code snippets, Tips & Tricks | Tagged , , , , | 5 Comments

Hook of the Month: taking control of email subscriptions

Are you familiar with Jetpack Subscriptions? This month, we’ll use filters to customize this module, and control which posts should be sent to your subscribers.

Jetpack’s Subscriptions module sends an email to your subscribers every time you publish a new post. That’s practical, but sometimes you may not want to bother your subscribers for something that might not be interesting to them.

Use filters to take control of Jetpack Subscriptions

Posted in Code snippets, Tips & Tricks | Tagged , , , , , | 13 Comments

Hook of the Month: Customizing the Top Posts & Pages Widget

Let’s kick off 2016 with a new series: welcome to the first installment of Hook of the Month!

Hooks are places in WordPress code where you can add your own code or change the default behavior of WordPress. Jetpack includes many of those hooks — 430 at the time of writing. In this series, I’ll introduce you to a new hook every month.

Today, let’s look at hooks help you customize one of our most popular widgets, the Top Posts & Pages widget.

Continue reading → Hook of the Month: Customizing the Top Posts & Pages Widget

Posted in Code snippets, Jetpack News, Tips & Tricks | Tagged , , , , , , | 28 Comments

How to exclude a category from the Mobile Theme

If you’ve ever wanted to exclude a particular category of posts from being displayed by Jetpack’s Mobile Theme, you can use the following code in a functionality plugin:

// Check if we are on mobile
function jetpackme_is_mobile() {
 
    // Are Jetpack Mobile functions available?
    if ( ! function_exists( 'jetpack_is_mobile' ) )
        return false;
 
    // Is Mobile theme showing?
    if ( isset( $_COOKIE['akm_mobile'] ) && $_COOKIE['akm_mobile'] == 'false' )
        return false;
 
    return jetpack_is_mobile();
}
 
// Modify the main query on the home page for the mobile theme.
function jetpackme_modify_main_query( $arg ) {
    if ( jetpackme_is_mobile() && is_home() ) {
         $arg -> set( 'cat', '-1' );
    }
}
add_action( 'pre_get_posts', 'jetpackme_modify_main_query' );

You would need to replace the 1 in

$arg -> set( 'cat', '-1' );

with the ID of the category you want to exclude.

Looking for more mobile tips? You’ll find them here! And if you more general need help with the Mobile Theme, take a look at our support doc.

Posted in Code snippets, Tips & Tricks | Tagged , , | Comments Off on How to exclude a category from the Mobile Theme
  • Join 78.8K other subscribers
  • Browse by Topic