I am building a child theme in WordPress that needs some custom functionality (for an example, I want to show an author bio on things in the ‘fiction’ category, but not in the ‘fiction-contest’ category, though they otherwise look the same).
It seems that no matter how specific my templates are, eventually I run into one of two things:
the_content();
or
get_template_part( 'content', get_post_format() );
This is the part I want to have finer control over. Yet it seems I can only grab content as a big chunk. My workaround has been to style parts of the content as “display: none”, depending on the template being used, but is there a way to conditionally change actual content returned by the above code? If so, how and where would I do that?
the_content() should return only the post contents. The author information should not be included unless the author explicitly listed it within the post.
I believe you are looking for something along the lines of:
Being that you are creating your own theme you can easily use the function get_the_content()… This will give you the content without echoing it… the downside of this is the filters that apply to the_content() are no longer applied. You can get the content with the filters from the get_the_content() function by using apply_filters(‘the_content’, $content) with $content being the return variable sent by get_the_content()
A third option which was previously mentioned is to create your own filter… this would be best done in a plugin and would be able to be applied to any theme you may use in the future.