WordPress.org

Ready to get started?Download WordPress

Forums

Remove automatic white space in posts/pages content (4 posts)

  1. SJTR
    Member
    Posted 4 months ago #

    Hi all.

    I was wondering how I can remove the automatic white space inserted in WP posts and pages. There seems to be about 20 pixels of white space above the post content when viewing my child theme in the browser. I built the theme from scratch and tried some filters in functions.php but none of them seem to work. I can't upload the theme unfortunately for you to view but can post a code you would like to see.

    I tried using firebug but can't find anything. So it seems like WP automatically inserts these
    or <p> tags at the beginning of a post/page. I can't find any trace of these tags in the WP editor not WYSIWYG or HTML editor. Any chance you guys know what's causing this 'automatic white space' and how to remove it?

    Thanks and regards

  2. mechx1
    Member
    Posted 4 months ago #

    Can you post a URL for your site?

    You can usually write a CSS selector to control margin/padding for the paragraph tag. Without seeing the site and the theme you are using, there is no way to be more specific.

  3. SJTR
    Member
    Posted 4 months ago #

    Hi,

    Well I don't have any way to post it online right now, but I'm thinking it has to do with WP in general. Like it's caused by the WP 'mother' theme. Just like when writing a post in the WP editor, you also get this white space on top of your content. Would you need to see any specific code?

    I also tried controlling the <p> tag in the CSS, specific and non-specific but the top white space remains there. Only the paragraphs shift, but what I want is the whole content loaded to be in a zero position. You see, I used this bit of code:

    <?php
    // must use a variable for page id
    // http://codex.wordpress.org/Function_Reference/get_page
    $id = 51;
    $p = get_page($id);
    echo apply_filters('the_content', $p->post_content);
    ?>

    to call in post content in a custom template. Content is called in a div.

    Regards

  4. SJTR
    Member
    Posted 4 months ago #

    Ok, so apparently there was an image and text link in my post surrounded by a h4 tag. I removed the tag and the content shifted a bit towards the top.

    Then I added;

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

    to the functions.php.

    This seemed to do the trick. Now the content loaded perfectly lines up the top of the div.

    EDIT: Ok this doesn't work perfectly. The content loads to the top, but all the <p> tags disappear. So there is no more any way to use enters in the WP post editor. Unless maybe custom inserting a <p> tag in HTML mode? That seems rather too much work.

    So basically just want to remove the first <p> tag.

    Any ideas?

Reply

You must log in to post.

About this Topic