• Resolved acellar

    (@acellar)


    Hi

    I’m trying to figure out how can i show a picture above the title on a sinlge page like on a “normal blog post”.

    Any advice would be great.
    Thank you!

    Regards,
    Adrian

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    If you add this code to your functions.php file in your child theme, it will add an image above the main container for all blog posts. Be sure to replace the image source with the url for your image.

    add_action('__before_main_container', 'add_image', 5);
    function add_image(){
    	if(is_single){
    		echo '<img src="your/img/url/here">';
    	}
    	else{
    		echo '';
    	}
    }
    
    Thread Starter acellar

    (@acellar)

    Thank you very much! That is perfect, i had to change it slightly to work for me…otherwise the picture comes up on every page / post….

    add_action('__before_main_container', 'add_image', 5);
    function add_image(){
    	if(is_page ( 'PAGETITLE'))
    	{
    		echo '<img src="your/img/url/here" />';
    	}
    	else{
    		echo '';
    	}
    }

    The picture is not strechted (witdh) to the full size of the page, how i can do that?
    Do i have to insert some html code into the function?
    Thank you!

    Cheers Adrian

    • This reply was modified 8 years, 2 months ago by acellar.
    • This reply was modified 8 years, 2 months ago by acellar.
    Thread Starter acellar

    (@acellar)

    I think i found now a way according to the article:https://presscustomizr.com/snippet/add-a-specific-page-or-post-content-in-another-post-or-page/

    function display_content_before(){
       if (!is_page ( '%PAGE-TITLE%'))
            return;
        ?>
        <div id="tc-reset-margin-top" class="container-fluid" style="margin-top: 138px;"> </div>
        	<div class="row-fluid tc-single-post-thumbnail-wrapper __before_main_wrapper">
    	    	<section class="tc_thumbnail span12">
    	    		<div class="">
    		    			<a class="tc-rectangular-thumb">
    		        			<img class="attachment-slider-full tc-thumb-type-thumb wp-post-image wp-post-image tc-smart-loaded h-centered" src="%PICTURE-URL&" alt="" style="display: inline; height: 300px; opacity: 1;">
    		    			</a>
    		    	</div>
    	    	</section>
    		</div>
    	</div>
        <?php
    }
    add_action  ( '__before_main_wrapper', 'display_content_before', 0 );

    But the image is not responsive on mobiles and when i click on the menu on my mobile the header is than beneath my picture which i have defined…
    You can see it here –> https://cellarbeans.ch/eine-seite/wo-wir-schon-waren/

    Thank you for your help.

    Cheers Adrian

    Thread Starter acellar

    (@acellar)

    Forget this post… i’m using a slider now.
    Cheers

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Single Page – Show picture before title…’ is closed to new replies.