We can use WordPress’s is_page_template conditional to enqueue our script just in these cases: if( is_page_template( 'page-complete-gallery. Let’s say the filename for our template for masonry pages is page-masonry-gallery.php. You can use the ispage( landing-page-template-one ) conditional around your page specific styles / scripts as part of your over-all enqueue statements. In our use case above, we might want to load our masonry library for pages using a special template for masonry pages. You can find many of them in WordPress’s Theme Developer Handbook. I am building a wordpress theme with a theme dashboard with options, but as I read somewhere, the enqueue script code I am using just enqueues it in the backend but it loads in every page in the backend. There are a whole host of useful conditional tags in WordPress. wpenqueuescripts is the proper hook to use when enqueuing scripts and styles that are meant to appear on the front end. When we enqueue our scripts, we can use a PHP if statement to load scripts only when needed. I have a few pages that will not require jQuery to be loaded in the header. blue-planet-child.zip WordPress Blue Planet Child Theme install file for Blue Planet Parent WordPress Theme version 3. Within the action hook, you can use several functions and embed them in the functions. Let’s go through the basics of the wpenqueuescript hook that you’ll use to load your assets. Use caution if implementing the solution below. We now know what enqueueing is and how it works. Here is an example of loading a masonry library through enqueueing: wp_enqueue_script('masonry', get_stylesheet_directory_uri(). Note: Removing jQuery that comes with Wordpress is not recommended. With this article, we’ll look at some examples of How To Add Script In WordPress Admin Page problems in programming. This is the recommended method of linking JavaScript to a WordPress generated page. First, though, if you are not familiar with loading JavaScript using WordPress’s wp_enqueue_script function, you can learn more about that from the WordPress developer documentation. How To Add Script In WordPress Admin Page With Code Examples. all the parameters necessary to link a script. ![]() Fortunately, conditionally loading a JavaScript in WordPress is pretty simple. It seems like a waste to load something like a Masonry library on every page when it may never be needed. I have often found myself building a website where only one or two pages need some JavaScript functionality.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |