skip to Main Content

I would need to add a javascript code within a specific page of my wordpress site.
I would like to find a solution via plugin, otherwise maybe I could modify the code I already use specifying the page, but I don’t know how to do it

This is my code:

( function( $ )  {

    $(document).ready( function() {
        $('.title_subtitle_holder_inner > h1:nth-child(1) > span:nth-child(1)').text('EVENTI');
    });

})( jQuery );

I would need that text to be edited on a specific page, in my case the page id would be 217

Thank you

2

Answers


  1. Probably no harm in injecting that minimal code into all pages, just make it so that it selects elements only when on your specific target page.

    WordPress creates a class page-id-XY on the body element automatically, so just prepend your selector accordingly, so that it will only select elements on that specific page:

    $('body.page-id-217 .title_subtitle_holder_inner > h1:nth-child(1) > span:nth-child(1)')
    
    Login or Signup to reply.
  2. You can try to use this:

    https://wordpress.org/plugins/page-specific-scripts/

    Or any other method for custom scripts on specific page. From what I recall I think WordPress has this functionality built in.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search