• I include a disclosure statement at the beginning of each blog post. Does anyone know of a way to exclude certain text from a WordPress homepage excerpt with CSS/HTML or PHP?

Viewing 7 replies - 1 through 7 (of 7 total)
  • You could add the disclosure text as a Custom Field instead of it being directly within your content, you can display the contents of a custom field using this PHP code (anywhere within The Loop):

    echo get_post_meta($post->ID, 'customfieldnamehere', true);

    This will separate the disclosure from your post contents so it will never be a part of the excerpt. You can also do other things with this separated custom field like wrap it in a CSS class and style it differently for example.

    echo '<div class="my-disclosure">' . get_post_meta($post->ID, 'customfieldnamehere', true) . '</div>';

    In your stylesheet you can then use this:

    .my-disclosure {
        font-weight: 700;
        font-style: italic;
    }

    Hope this helps.

    Thread Starter parchmentgirl

    (@parchmentgirl)

    Thanks!

    Thread Starter parchmentgirl

    (@parchmentgirl)

    One more question – After adding in the disclosure, it now shows up beneath the title of every single post in my archives. (See here: https://parchmentgirl.com/find-a-post)

    Is there a way to change that so it only shows up on individual posts?

    Also, I ended up using HTML for the disclosure with a hooks plugin for the disclosure. Here is the HTML for the hook in case it’s relevant:

    <div class="disclosure">
        <p>Disclosure: This post may contain affiliate links. Some books were provided by publishers. </p>
    </div>

    You could make use of custom fields to control the visibility on a per-post basis, they’re very useful.

    <?php if (get_post_meta($post->ID, "customfieldnamehere", true)) { ?>
        <div class="disclosure">
            <p>Disclosure: This post may contain affiliate links. Some books were provided by publishers. </p>
        </div><?php
    } ?>

    The above disclosure would only be displayed if a post has a custom field called “customfieldnamehere”, if the custom field is left empty on a post then the disclosure won’t be triggered on that particular post.

    Hope this helps.

    • This reply was modified 7 years, 11 months ago by ThemeSumo.
    Thread Starter parchmentgirl

    (@parchmentgirl)

    It’s not that I don’t want it to show up on certain posts (although, I would like to exclude it from pages…is there a way to do that?), it’s that I don’t want it showing up in my archives.

    How are you hooking your disclosure into the theme?

    You could wrap it, or the above custom field code, within a is_archive conditional to remove it from archives, like so:

    if (!is_archive()) {
        // stuff
    }
    Thread Starter parchmentgirl

    (@parchmentgirl)

    I’m using the Genesis Simple Hooks plugin to hook the HTML in my previous reply to the entry header.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Exclude Text from Home Page Excerpt’ is closed to new replies.