• Resolved sharonbeyond

    (@sharonbeyond)


    in this site more post section we need to hide this certain text “Originally posted on the Bibles for America Blog” in home page but need to be visible in single post’

    after adding necessary code in functions.php and css , the text still shows in home page along with few other texts : (Originally posted on the Bibles for America Blog) Did you know that besides offering free copies of the New Testament Recovery…

    Function.php code:

    function hide_text_on_homepage($content) {
    // Check if it’s the homepage
    if (is_home() || is_front_page()) {
    // Text to hide on the homepage
    $text_to_hide = ‘Originally posted on the Bibles for America Blog’;

        // Replace the text with an empty string
        $content = str_replace($text_to_hide, '', $content);
    }
    return $content;

    }
    add_filter(‘the_content’, ‘hide_text_on_homepage’);

    CSS code:
    body.home .bfalink {
    display: none !important;
    }

    html code:
    <p class=”bfalink” style=”font-size:12px”><em>(Originally posted on the <a href=”https://blog.biblesforamerica.org&#8221; target=”_blank” rel=”noreferrer noopener”>Bibles for America Blog</a>)</em></p>

    The page I need help with: [log in to see the link]

Viewing 10 replies - 1 through 10 (of 10 total)
  • Moderator bcworkz

    (@bcworkz)

    CSS alone should work. However, you home page doesn’t have a “home” class. It does have a “blog” class.

    body.blog .entry-content p {
       display: none !important;
    }

    Add to the Additional CSS section of the customizer or style book. Beware that caching can confuse the effectiveness of added CSS. If this does not appear to work, clear all caches, client and server side.

    the_content filter approach can work as well, but the forum formatting has mangled your code to the point it’s difficult to repair. Thus I’m unable to test it or even evaluate what might be wrong.

    Thread Starter sharonbeyond

    (@sharonbeyond)

    @bcworkz Thank you. https://bfausblogdev.wpengine.com/ in this site home page has a section called moreposts, in that section we have use ACF latest post block..(Originally posted on the Bibles for America Blog). Only this text needs to be hidden in the home page.

    Moderator bcworkz

    (@bcworkz)

    There’s nothing CSS can do to distinguish the undesired phrase from the rest of the excerpt. You would need to either prevent its insertion to begin with, or remove it later via a filter hook and string search/replace.

    Is the phrase part of the post content as saved? Or is it injected into posts by some other mechanism? If it’s required for all single posts, it’s preferable to automatically inject it when is_single() returns true. But if there are lots of posts where it’s already part of post content it may not be worth the effort.

    It could be using str_replace() in a callback for “the_content” is the best approach. If you could re-post your code in a single code block so that it remains un-corrupted, I’d be willing to take a closer look at it.

    Thread Starter sharonbeyond

    (@sharonbeyond)

    Thank you @bcworkz Using your instructions, I was able to hide that specific text in home. There is anyway that can be hidden overall, even in the related posts section. This should be seen only in single post

    Moderator bcworkz

    (@bcworkz)

    There is probably a way. It depends on what you ended up doing to hide the home page text. For example, if using a CSS solution your selectors to hide might be
    body.blog .entry-content p, :not(.single) .entry-content p

    Or if you’re using PHP, a conditional statement such as
    if ( is_front_page() || ! is_single()):

    Thread Starter sharonbeyond

    (@sharonbeyond)

    body.blog .entry-content p, :not(.single) .entry-content pBy using this CSS, it takes up the entire content of the home page.
    (Originally posted on the Bibles for America Blog). has a separate class name.

    We have added a code in function.php to hide the text on the home page and the pagination page (archive page). code:

    function hide_text_on_homepage($content) {
        if (is_home() || (is_front_page() && has_body_class('blog'))) {
            // Text to hide on the homepage
            $text_to_hide = '(Originally posted on the Bibles for America Blog)';
            
            // Remove the text and empty parentheses from the content
            $content = str_replace([$text_to_hide, '()'], '', $content);
        }
        return $content;
    }
    add_filter('the_content', 'hide_text_on_homepage');
    
    
    function hide_text_on_pagination_pages($content) {
    	if (is_archive() && has_body_class('blog paged')) {
    			// Text to hide on pagination pages of archives
    			$text_to_hide = '(Originally posted on the Bibles for America Blog)';
    			
    			// Remove the text and empty parentheses from the content
    			$content = str_replace([$text_to_hide, '()'], '', $content);
    	}
    	return $content;
    }
    add_filter('the_content', 'hide_text_on_pagination_pages');
    
    

    For the home page, it works, but not for the pagination page.For example, we need to hide that specific text even in this: https://bfausblogdev.wpengine.com/page/2/

    Moderator bcworkz

    (@bcworkz)

    Sorry, corrected CSS selectors:
    body.blog .entry-content p, :not(.single) .entry-content p.bfalink

    has_body_class() is not a WP function. Have you defined one for this? It could call get_body_class() and see if a single passed class term is part of the returned array using in_array().

    ! is_single() did not work? You might try a slight variation ! is_singular()
    (for a single post of any post type, is_single() is only true for single “post” post type)

    Another possible conditional check is for a particular query var value returned by get_query_var(). You could check the “paged” value this way.

    Thread Starter sharonbeyond

    (@sharonbeyond)

    `@bcworkz Will this code help to fix this :

    function hide_text_on_pagination_pages($content) {
    // Check if it’s an archive page and not a category page
    if (is_archive() && !is_category() && is_paged()) {
    // HTML code to hide on pagination pages of archives
    $html_to_hide = ‘<div><p style=”font-size:12px”><em>(Originally posted on the <a href=”https://blog.biblesforamerica.org”>Bibles for America Blog</a>)</em></p></div>’;

        // Remove the HTML code from the content
        $content = str_replace($html_to_hide, '', $content);
    }
    return $content;

    }
    add_filter(‘the_content’, ‘hide_text_on_pagination_pages’);

    • This reply was modified 1 year, 2 months ago by sharonbeyond.
    Moderator bcworkz

    (@bcworkz)

    ˉ\_(ツ)_/ˉ maybe? ??
    It depends on what conditions you need the removal code to work on. Those conditions wouldn’t apply to the home page wouldn’t they? The is_paged() check should maybe be with OR logic? I’m not 100% sure what conditions you need, perhaps:

    if (is_front_page() ||
       ( is_archive() && ! is_category()) ||
       is_paged()) {

    in this site more post section we need to hide this certain text “Originally posted on the Bibles for America Blog” in home page but need to be visible in single post’

    It depends on what conditions you need the removal code to work on.

    To OP: Perhaps you want to remove this text everywhere on the site, except the single POST page ONLY?

    The text in question is the first paragraph of the affected posts. So every auto-generated excerpt for these posts will have this text. That means the text will appear wherever the_excerpt() is called, including even (in this case) the on-site search result listings.

    So I would match everywhere except the single post, but, of course, OP may have a different requirement.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘need to hide a specific text in home page’ is closed to new replies.