Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #370866

    Hi,

    I would like to add “sponsored post” behind the post title.
    The code snippet for this is from WP Beginner and is this now at my functions.php:

    add_filter( 'the_title', 'wpb_sponsored' );
    function wpb_sponsored( $title ) {
    global $post;
    $sponsored_text = '<a href="http://xxxxxxxxxx.de/ueber"><span class="sponsored_text">Sponsored Post</span></a> ';
    $sponsored = get_post_meta($post->ID, 'sponsored', true);
    if( $sponsored == 'true' && in_the_loop() ){
    return $title.$sponsored_text;
    }
    return $title;
    }

    This code works fine with other themes like Twentythirteen etc., but not with ENFOLD, because there is a double part of this “sponsored” code, when you hover over the post title. See the screenshot please, because my site is still offline:


    https://screencloud.net/v/gFRp

    • pink arrow: the “sponsored post” text is okay
    • green arrow: in the permalink of the post title is the code snippet, the link for the “sponsored post” text, so it is in the source code as well – and therefor the code for the permalink post title is destroyed.

    As the code snippet works in other themes well, the reason might be in the loop-index.php of ENFOLD.
    Could anybody help me out please?
    Thanks.

    (site is in maintenance mode, sorry)

    #371138

    Hey!

    The problem is there is a function that alters the Posts titles (/enfold/includes/helper-post-format.php:54):

    	function avia_default_title_filter($current_post)
    	{
    		if(!empty($current_post['title']))
    		{
    			$heading = is_singular() ? "h1" : "h2";
    	
    			$output  = "";
    			//$output .= "<{$heading} class='post-title entry-title ". avia_offset_class('meta', false). "'>";
    			$output .= "<{$heading} class='post-title entry-title' ".avia_markup_helper(array('context' => 'entry_title','echo'=>false)).">";
    			$output .= "	<a href='".get_permalink()."' rel='bookmark' title='". __('Permanent Link:','avia_framework')." ".$current_post['title']."'>".$current_post['title'];
    			$output .= "			<span class='post-format-icon minor-meta'></span>";
    			$output .= "	</a>";
    			$output .= "</{$heading}>";
    	
    			$current_post['title'] = $output;
    		}
    
    		return $current_post;
    	}

    You can put a modified version of this (merged with your initial filter code) in your child theme functions.php.

    Best regards,
    Josue

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.