You need to add it to a JS file and then enqueue it in your functions.php
jQuery(document).ready(function($){
$('p').wrap('<div class="post-txt" />');
});
If you already have a js file, you can add it to that file and you’re done.
Else, save the above snippet in a new file. Put that file in a folder called js
in your theme folder(for the sake of clean code). Let’s say you called that file wrap.js
.
Add the following in your functions.php
file:
function wpse_134325_scripts() {
wp_enqueue_script( 'wrapper', get_template_directory_uri() . '/js/wrap.js', array('jquery') );
}
add_action( 'wp_enqueue_scripts', 'wpse_134325_scripts' );
You can read more about enqueing scripts on the Codex.
Related Posts:
- Looking to exclude blog posts from category Previous/Next buttons
- Loading index.php contents which located outside blog folder for post single page
- Post repeating with infinite scroll
- How to use a PHP file to control the content of a blog post
- LinkedIn Share Post Button
- Let user select the number of posts shown per page jquery error
- How can I add WordPress Audio Player as featured audio in Audio Blog Posts?
- Display posts based on the selected category when no subcategory is chosen
- Remove posts after a given amount of time
- Automatically add custom CSS to new posts using a category template
- How to filter posts by post format “standard” from wp-json api?
- How to test nonce with AJAX – Plugin development
- How Display Posts on category
- Hide wordpress field if data is empty in post!
- Woocommerce add to cart quantity buttons with AJAX
- Customize Time Stamp
- How can I use wp_query to show all product data using just the products ID?
- js file in root loading without
- hover image appears below placeholder instead of overlayed
- combine Code 1 with Code 2
- WooCommerce – Reset quantity input field when variation changes
- Query all posts of a custom taxonomy term
- class click counter save number
- Retrieving Author ID in wp-admin area
- Get first URL from post content
- Remove certain post-formats from showing in blog?
- Slider loading issue
- Checking for new message using AJAX and PHP. Server overload?
- Getting a specific post values to another div or modal
- jQuery not defined
- AJAX request status 200 but no actual “response”
- Trying to add attribute to my posts’ featured image
- Conditional Header in wordpress
- How do I ensure that a piece of hard code only gets called, when on my appointed Blog page?
- Displaying the last post on static homepage
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Can’t get wp_insert_post to work
- Why not yield/iterable in posts interface?
- How to select the contents in the text view textrea in wp_editor?
- Best practice for migration friendly images in posts/pages?
- Where in PHP do I move title and meta (date) to bottom of each blog section?
- How do I use this PHP library to access OpenGraph data in a child theme?
- wordpress count link clicks by ip address
- Proper syntax or method for keeping url in modified isotope / category links
- How to show part of the_content?
- WordPress add post format support not working
- ajax, right way to do it and make it works?
- How to make number of blog posts a custom field?
- Is there a way to programmatically create multiple pages utilizing the same template but different content from a json file?
- Unreadable pagination
- 200 Rewrite blog post links
- Ajax load more posts with multiple tax query
- How to set a min number of words for a blog post
- WordPress Sending data to Ajax with select option
- Loop through categories and display posts title under each dropdown
- WordPress ajax doesn’t display object method on jQuery .change() function
- Get post id in a function when edit/add a post
- Ajax loaded form replaces form action with Ajax url
- prevent default not stopping page refresh. Passing form information to and from php with ajax in a wordpress site
- how do I get a specific post from a post with a subcategory in WP
- How to design a table based on css values set from admin/dashboard
- Automatically create child pages and grandchild pages when saving a (parent) page
- Pass Category Name, Description and Photo into variables to pass to jQuery
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Adding Custom Slider
- Second transition_post_status hook fired instead of the first
- Ajax date_query not working past the first iteration
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- How to store post ID’s in cookie or session to display the same posts later
- AJAX pagination, update current page
- Limit Widgets to Sidebar ID’s
- Which hook/action will help me solve my problem?
- Save Search System
- adjust section according to country?
- populate form fields in a loop with ajax
- How can I add extra word in permalink when someone click download button?
- trigger html cleanup for all posts
- dynamic dependent select dropdown
- Change “add to cart” button color based on Woocommerce product category [closed]
- How can I get the values of my WordPress $wpdb query in Jquery?
- Ajax request returns ‘Array’. How to output the actual results?
- Blog posts repeat
- Ajax load more button for comments wordpress
- Post + form + action + results on the same page
- Slick + PHP + ACF + JQuery slide reveal not working
- Open post-content in archive page in a Modal box with bootstrap
- How to add a do_action on refreshing of WP customizer?
- Gravity form built in Captcha
- Menu jumping when calling it via PHP
- remove post that has no content
- Different post styles depending on category
- Setting value of session with Ajax not working
- Click a radio button must set textfield value
- WordPress Multiple Navigation bars
- [jQuery]Adding shortcode
- multiple taxonomy select display only one in front end
- Display parent and child taxonomies in separate drop down select fields
- Show success or error messages in Ajax response to WordPress custom registration form
- How to add a Custom Mailchimp AJAX Newsletter Subscribe Form