What WP Plugin Allows You To Inject Code Into Specific Pages?

Joined
May 9, 2015
Messages
238
Likes
64
Degree
0
I need to inject FB event code into certain pages. I can't find a plugin that will allow me to do this as the one I'm using right now only allows me to inject into all pages at once.

What do others recommend?
 
Advanced Custom Fields (ACF). Create a text area field and set it show on all pages. Then in your theme add a line that says if this field is not blank show the field with your tracking code.
 
We just install Google Tag Manager, and handle everything else in that.
There is a learning curve, but in the long run its much simpler, especially if you manage lots of sites
 
The easiest way to do this is to work in the functions.php. Absolutely make sure you're using a child theme if you want to keep these changes in the long-term. If you don't, and then update your theme, you'll lose the changes.

Inside the functions.php file, you can add one of the following, where we understand that if you're trying to add it to a post, you use is_single() and if trying to add it to a page, you use is_page(). Also, within the parenthesis you will add the Post or Page ID for the correct page. It is a number like is_single(17). If you want to add the same code to multiple pages you can use an array like this: is_single(array(17,28,37))

Code:
/* For Adding Scripts to the Header on a Specific Post (using Page ID): */
function ryu_head_script() {
    if ( is_single(17) ) {
        echo ' your script goes in these quotations ';
    }
}
add_action('wp_head', 'ryu_head_script');

Code:
/* For Adding Scripts to the Footer on a Specific Post (using Page ID): */
function ryu_foot_script() {
    if ( is_single(17) ) {
        echo ' your script goes in these quotations ';
    }
}
add_action('wp_footer', 'ryu_foot_script');

Code:
/* For Adding Scripts After Body Tag Opens on a Specific Post (using Page ID): */
function ryu_body_script() {
    if ( is_single(17) ) {
        echo ' your script goes in these quotations ';
    }
}
add_action('wp_body', 'ryu_body_script');

This last one: wp_body() is new, really new. It's unlikely your theme has it integrated. But if so, or you have a child theme and want to add it yourself, it's fairly simple to use. You can place the hook <?php wp_body(); ?> at the opening of the body tag or right before it closes, depending on your needs.

If none of this makes sense or you aren't sure how to find your Post ID or Page ID, definitely find a plugin or hire someone.
 
Back