Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 176 Vote(s) - 3.64 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove auto added <p> from a page that has no literal content (uses shortcodes)

#1
I have a WordPress powered website that on the homepage uses a static page with nothing but shortcodes to generate the content.

The page gets these shortcodes by setting the front page to a static page and using the_content(); on page.php. The page content has no spaces, only shortcodes, so looks something like this:


[content-shortcode blah blah][more content-shortcode blah blah]


It all works fine, except that WordPress adds an empty `<p></p>` before the shortcodes code and another P /P at the end of all the shortcodes code (Nothing in between shortcodes).

How can I remove them? I do not want to disable the global wpautop removal function though, as it can be useful for some users, I only want to remove the first and last P's that appear on the homepage.
Reply

#2
There are various functions aside from `wpautop()` that [filter post content][1], such as `force_balance_tags()`, which was designed to balance bad HTML coming in via the editor.

They're mostly defined in [formatting.php][2], where you can see the various code in source.

Removal of these filters can be as simple as one line, as you point out:

`remove_filter('the_content', 'wpautop');`

For more information:

[To see links please register here]



Check out below links which will help you.

1.

[To see links please register here]

2. [wordpress-wrapping-shortcodes-with-p-tags][3]
3. [Disable wpautop Plugin][4]

may this help you.


[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

[4]:

[To see links please register here]

Reply

#3
Try this(paste this code somewhere in `functions.php`):

function shortcode_empty_paragraph_fix($content){
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);

$content = strtr($content, $array);
return $content;
}

add_filter('the_content', 'shortcode_empty_paragraph_fix');

Reply

#4
Since you want to only remove `<p>` tags on the home page, add the code below to your `functions.php` file:


add_action('pre_get_posts', 'remove_autop_from_home');
function remove_autop_from_home() {
// check to see if we are on the home page
if(is_home()) {
remove_filter('the_content', 'wpautop');
}
}
Reply

#5
There are a few things you can try.

You can pospone the `wp_autop` because it processes before the shortcode output:

remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 12);

Or use the [`cleanup_shortcode_fix()`](

[To see links please register here]

) function that should help with your issue:

function cleanup_shortcode_fix($content) {
$array = array('<p>[' => '[', ']</p>' => ']', ']<br />' => ']', ']<br>' => ']');
$content = strtr($content, $array);
return $content;
}

add_filter('the_content', 'cleanup_shortcode_fix');
$string = preg_replace_('/<p>s*</p>/', '', $string);
add_filter('the_content', 'cleanup_shortcode_fix', 1);
Reply

#6
jQuery('p:empty').remove();
Also you can use JS. Above code will help you to remove all empty p tag from the page
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through