WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Hide Post Author & Date - specific issue... (50 posts)

  1. thescarletfire
    Member
    Posted 1 year ago #

    Hello,

    I am trying to get WordPress to hide author, date, and the "bookmark the permalink" - but ONLY in posts of a certain category. I know how to do a universal site-side change of this, but I don't want to hide this data from other blog posts and categories, just a particular category.

    Is this possible? Can you please tell me what code I'd need to adjust for this? Thank you so much. I can't complete my job here unless I solve this...

  2. cinghaman
    Member
    Posted 1 year ago #

    you would have to make a conditional logic function something like

    if(is_category(id1,id2, id3)
    {
    hide info
    }

  3. thescarletfire
    Member
    Posted 1 year ago #

    Assuming I knew the category ID (which I know how to find), what file would I enter that code into? If it's just one category and not all pages/posts...

    Also, when you write "hide info", what actually goes in between the {} in that example? Like, "entry-author" ? I'm a bit confused.

    Thank you so much for trying to help me, you're a true lifesaver.

    How should I proceed?

  4. cinghaman
    Member
    Posted 1 year ago #

    it will go into your functions.php file (preference would be if you create a child theme and not modify the core files)

    i usually do for hide info thing is use css
    <?php
    if (is_category('id'))
    {
    echo ' <style> #author {display:none;} #time {display:none;}
    </style>';
    }
    ?>

  5. thescarletfire
    Member
    Posted 1 year ago #

    Thank you Robin, I will try that code and mess around with it. If this works, I'll hurry back and let you know that you saved the day.

    I wish I was a guru like so many people here are :)

    Thanks again,
    Ben

  6. cinghaman
    Member
    Posted 1 year ago #

    cheers

  7. thescarletfire
    Member
    Posted 1 year ago #

    Hmm...is there a particular location in the functions file that this code should go in? Like, between other code, or at the very end, or etc.

    Thank you!

  8. cinghaman
    Member
    Posted 1 year ago #

    i put my code on top

  9. thescarletfire
    Member
    Posted 1 year ago #

    Well, no matter where I seem to place it in the php file, I get this sort of error:

    Parse error: syntax error, unexpected '<'

    I'm copying your code exactly, so perhaps I'm putting it in the middle of some code I should not be breaking up?

    Is there a surefire way to know where I can put it where it will be safe and work correctly?

    Thank you!

  10. cinghaman
    Member
    Posted 1 year ago #

    my code was just a reference guide
    and if you are getting this error means you are not closing your tags properly or missing a bracket
    and if you put it on top under your
    <?php ?>
    it should not break

  11. thescarletfire
    Member
    Posted 1 year ago #

    Ah, yes ok - I thought I maybe forgot to close off the PHP with ?> or something - but it looked right.

    I'll try and put it at the top under the <?php ?> - thanks again!

  12. cinghaman
    Member
    Posted 1 year ago #

    <?php
    if ( is_user_logged_in()  )
      {
       echo ' <style>
    
    	</style>';
    } else {
    
    	echo ' <style>
    
    	html {
        background-color:#FFF !important;
    }
    
    	</style>' ;
    }
    ?>

    this is my working code

  13. thescarletfire
    Member
    Posted 1 year ago #

    ...? You lost me... :)

  14. cinghaman
    Member
    Posted 1 year ago #

    i mean if you follow the structure of my code it should work , as this is the code i am using in one of my sites

  15. cinghaman
    Member
    Posted 1 year ago #

  16. thescarletfire
    Member
    Posted 1 year ago #

    Ah, yes - good news. The code no longer has a syntax error, but it doesn't hide any data - so maybe the CSS does not match?

    if (is_category('23'))
    {
    echo ' <style> #author {display:none;} #time {display:none;}
    </style>';

    This doesn't return an error but the author and time are still showing up in that category for posts.

    Hmmm...any ideas? You seriously are saving my tail here...

  17. cinghaman
    Member
    Posted 1 year ago #

    haha :P
    as i said it was just a reference guide
    #author and #time r no id/classes

    i just gave you a syntax
    you have to see which classes/ ids r being used in your code

  18. thescarletfire
    Member
    Posted 1 year ago #

    Doh! Epic fail - gotcha - I'm on it.... :) Thanks!

    Checking out the CSS now...

  19. thescarletfire
    Member
    Posted 1 year ago #

    I only see .entry-author (span) as being how the CSS is stying the post author, etc.

    I modified the code with the class but it's still not working.

    Is there any way to dig deeper and find the #ID I need to input in the functions file?

    I am using Google Chrome Dev tools, I prefer it vs. FireBug :)

    Thanks!

  20. thescarletfire
    Member
    Posted 1 year ago #

    Success!
    (sort of lol)

    I entered this in the functions file:

    function jl_remove_post_dates() {
    add_filter('the_date', '__return_false');
    add_filter('the_time', '__return_false');
    add_filter('the_modified_date', '__return_false');
    add_filter('get_the_date', '__return_false');
    add_filter('get_the_time', '__return_false');
    add_filter('get_the_modified_date', '__return_false');
    } add_action('loop_start', 'jl_remove_post_dates');

    But it removed the date from ALL posts, regardless of category. Before you leave me, can you just help me fit in your conditional code so my above function will ONLY hide date on Category ID=23?

    Thank you SO much! :)

  21. cinghaman
    Member
    Posted 1 year ago #

    i would have to see your site to see which classes are working on it

    not sure but you might try calling this function inside the conditional loop

  22. thescarletfire
    Member
    Posted 1 year ago #

    Hmm..I really can't figure this out.

    I'll be happy if I can just at least remove the date and "bookmark to permalink" text from ALL posts in a particular category - not all posts in all categories.

    Any chance you, or another kind soul can please help me out with this?

    Thank you again.

  23. cinghaman
    Member
    Posted 1 year ago #

    it would be good if you could post your link

  24. thescarletfire
    Member
    Posted 1 year ago #

    Well my site is currently offline (Maintenance Mode) - is there a way to let you 'see' my FTP files without being able to destroy them? :) Read only?

    Thanks!

    I mean, I guess I could add you to the blog as a user, temporarily - yes?

  25. thescarletfire
    Member
    Posted 1 year ago #

    I'll just make my site online for like 10 mins or so - and you can grab/look at whatever files you need to...gimme one minute :) Thanks!

  26. cinghaman
    Member
    Posted 1 year ago #

    cool

  27. thescarletfire
    Member
    Posted 1 year ago #

    Ok, so a few things -

    First, seriously - THANK YOU. You are seriously saving my job. I'm the webmaster for this website and I recently took it over - I have a strict deadline of this weekend...

    Second, please note that the ultimate goal here is to hide/remove certain text from the single posts AND the category's 'main' page - not just one location, but both. I have included screenshots to show you the parent category page, and the post in that category - I need the text to be gone from both locations.

    Finally, if there is anything I can do to show my appreciation, please let me know. I can't thank you enough....here is the website data:
    (I just recently took over so bear with me, I'm still learning the code here)

    First, images to help you see my goal:
    Image 1 - This shows the Category's MAIN page, which displays all posts within that category (Category name = Compositions).
    http://i.minus.com/jbzFbcceOfuWOU.jpg

    Image 2 - This shows the individual post WITHIN the Compositions category - all highlighted text, I would like to be hidden.
    http://i.minus.com/jVY5aoVz0Lkfc.jpg

    The website is:
    http://www.benjamincl.com

    Please, if you could help me tonight that would be awesome (it's 9PM EST here) - my boss would kill me if he knew the site was live online now lol - thanks again...I look forward to your help...

    Thank you,
    Ben

  28. cinghaman
    Member
    Posted 1 year ago #

    ha time differences :P its 1PM in new zealand

    ok in the original code i gave you
    <?php
    if (is_category(23) )
    {
    echo ' <style>
    .entry-date {
    display:none;
    }
    </style>';
    }
    ?>

  29. thescarletfire
    Member
    Posted 1 year ago #

    FYI:

    I went to school with the guy who owns this site - we're both named Ben....we hung out all the time, and were known as the Bens :)

    Thanks again for the help!

  30. cinghaman
    Member
    Posted 1 year ago #

    if (is_category(23) )
    {
    echo ' <style>
    .entry-date {
    display:none !important;
    }
    .entry-author{
    display:none !important;
    }
    .entry-cats{
    display:none !important;
    }
    entry-permalink{
    display:none !important;
    }
    </style>';
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.