admin管理员组文章数量:1291144
I am trying to set up blog posts so that when an image is added it is wrapped in one div set to float right and when text is added it is wrapped in another div set to float left. So that all images added to posts in the blog will always have images right and text left.
have tried using jQuery to wrap all p tags in a div like so
jQuery('p').wrap("<div class='post-txt'></div>");
But I cant work out which PHP file to add this to, so nothing appears to be happening.
Any help to point me to the correct PHP file within wordpress or any other options would be very much appreciated.
All the best
Harry
I am trying to set up blog posts so that when an image is added it is wrapped in one div set to float right and when text is added it is wrapped in another div set to float left. So that all images added to posts in the blog will always have images right and text left.
have tried using jQuery to wrap all p tags in a div like so
jQuery('p').wrap("<div class='post-txt'></div>");
But I cant work out which PHP file to add this to, so nothing appears to be happening.
Any help to point me to the correct PHP file within wordpress or any other options would be very much appreciated.
All the best
Harry
Share Improve this question asked Feb 12, 2014 at 11:40 Harry RookHarry Rook 12 bronze badges 1- 1 This actually is a XY problem. Please edit your question and explain clearly what part of the content your want to have wrapped in divs with this class. You don't need jQuery. – kaiser Commented Feb 12, 2014 at 13:06
1 Answer
Reset to default 1You 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.
本文标签: phpWrap posts p tags in div
版权声明:本文标题:php - Wrap posts p tags in div 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741499586a2381995.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论