Add html code to a page via theme based on body class (2 posts)

  1. iamaaronryan
    Posted 2 years ago #

    I would like to add some code to a theme that adds some html code to a page or post based on the body class of a page/post. The user would add a custom body class in the page/post editor when creating the post. Different custom classes would have different images displayed. Something like below:

    if body class="class name" {
    			echo '<img src="http://www.website.com/image.jpg">';

    Disclaimer, I have no php programming knowledge. My experience has been limited to being able to copy some code and use it other places.
    I know I have the first line completely wrong just trying to convey what I want to do.


  2. Michael
    Forum Moderator
    Posted 2 years ago #

    possibly use get_body_class() and check the returned array for "class name"



    if( in_array('class name', get_body_class()) ) {
    			echo '<img src="http://www.website.com/image.jpg">';


Topic Closed

This topic has been closed to new replies.

About this Topic