#32 – 2 Questions

Posted in ‘weeblrAMP’
This is a public ticket. Everybody will be able to see its contents. Only enter usernames, passwords or any other sensitive information in the Private information field.
Sunday, 28 May 2017 22:09 UTC
hidohebhi
1. The code you wrote for us previously for changing JSON-LD types to Recipe does not seem to be working (the code is below, with only the category # changed). Here's a page that should have the type changed but doesn't: https://paleomagazine.com/lemon-garlic-ghee-salmon-paleo-keto-aip/amp

Also - as an aside, we'd prefer to do it by tag, so I modified the code (the second version below), but it also doesn't work.

add_filter(
'weeblramp_json_manifest',
function ( $jsonld, $pageData ) {

// set document type based on post
$post = WeeblrampHelper_Content::getPostFromPageData( $pageData );
if ( ! empty( $post ) && 'single' == wbArrayGet( $pageData, 'request_type' ) ) {
$postCategories = wp_get_post_categories( $post->ID );
$recipeCategories = array( 603 );
// set document type
if ( array_intersect( $postCategories, $recipeCategories ) ) {
$jsonld['@type'] = 'Recipe';
}
}

return $jsonld;
},
10,
2
);

add_filter(
'weeblramp_json_manifest',
function ( $jsonld, $pageData ) {

// set document type based on post
$post = WeeblrampHelper_Content::getPostFromPageData( $pageData );
if ( ! empty( $post ) && 'single' == wbArrayGet( $pageData, 'request_type' ) ) {
$postTags = wp_get_post_tags ( $post->ID );
$recipeTags = array( 584 );
// set document type
if ( array_intersect( $postTags, $recipeTags ) ) {
$jsonld['@type'] = 'Recipe';
}
}

return $jsonld;
},
10,
2
);



2. Separate feature question - are you planning on allowing ads to be placed within the content? For us, this would be great, and I know many other food bloggers prefer this for ads.

Or, I imagine we could effectively use a filter like the one below (but with the correct weeblramp filter)?

add_filter('the_content', 'mte_add_incontent_ad');
function mte_add_incontent_ad($content)
{ if(is_single()){
$content_block = explode('<p>',$content);
if(!empty($content_block[2]))
{ $content_block[2] .= 'insert_ad_code_here';
}
for($i=1;$i<count($content_block);$i++)
{ $content_block[$i] = '<p>'.$content_block[$i];
}
$content = implode('',$content_block);
}
return $content;
};
Monday, 29 May 2017 06:45 UTC
wb_weeblrpress
Hi

1 - The problem is in the
$recipeTags = array( 584 );
bit.

wp_get_post_tags does not return the tags id. It returns a list of tags Object, so when you do array_intersect, well, those array do no intersect.

To get the ids, and thus be able to compare directly with a list of tags id, you should do something like this I think:

$postTags = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );


With categories, the problem is about the same, categories should be obtained asking only for the ids:

$postCategories = wp_get_post_categories( $post->ID , array('fields' => 'ids');


Don't remember exactly how it was working, I may have not tested it well enough?

Thanks for the report, I have adjusted the blog post I did about this.

2 - I understand, I have had that demand on Joomla as well. Currently, you would have to manually insert shortcodes in your content, as described in documentation here.

I have not gotten around to do something like you describe, for 2 main reasons:

1 - time vs priorities
2 - It's kinda complex when you think about it (for instance, it should only be applied on some post types (on blog, but not on WooCommerce. Some would want them on posts, but not page. And you want to avoid category pages, and non-pure content stuff, etc)

I will look at a simpler implementation, not requiring a lot of new settings.

Rgds
 
Tuesday, 30 May 2017 13:33 UTC
wb_weeblrpress
Hi

OK, so I could not resist, and I did something about inserting ads in content automatically. Here is a dev version, download it from this page.

So when you go to the Ads configuration tab, you have 2 new fields:



As per the help text, you can enter there, either for posts or for pages (or both):

- a list of paragraph numbers, eg 1,3,5: an ad will be inserted after paragraphs 1, 3 and 5
- something like /2 or /3, which will cause an ad to be inserted every 2 or 3 paragraphs, respectively

A paragraph is deemed a paragraph when it has at least 20 characters; There is a filter for that
add_filter(
	'autoinsert_ads_min_paragraph_length',
	function ( $minParagraphLength) {

		$minParagraphLength = 10;

		return $minParagraphLength;
	}
);


There is another filter to decide yourself if a paragraph should be deemed "short" and as such not be taken into account:

add_filter(
	'autoinsert_ads_is_short_paragraph',
	function ( $isShortParagraph, $paragraphText) {

		$isShortParagraph=  ; // whatever condition you like based on content
		return $isShortParagraph;
	}, 
        10, 
        2
);


Another filter is to decide if you want to auto insert ads on pages where you already have manually added an ad shortcode ('weeblramp_autoinsert_ads_if_shortcode').

Another filter exists for the rules themselves ('autoinsert_ads_rules'). Required if you want to auto insert ads in other post types.

And finally, you can enable/disable this autoinsert based on the post, the post categories, tags,etc:

/**
 * 3. Filter automatically inserted ads, based on category or tag
 */
add_filter(
	'weeblramp_autoinsert_ads_on_post',
	function ( $shouldInsert, $post ) {

		if ( ! empty( $post ) ) {
			$postCategories   = wp_get_post_categories( $post->ID, array( 'fields' => 'ids' ) );
			$isRecipe         = has_tag( 'recipe' );
			$recipeCategories = array( 12, 34, 56/*, 85*/ );

			// filter based on category
			if ( array_intersect( $postCategories, $recipeCategories ) ) {
				$shouldInsert = false;
			}

			// filter based on tag
			if ( $isRecipe ) {
				$shouldInsert = false;
			}
		}

		return $shouldInsert;
	},
	10,
	2
);



Please let me know how it works for you.

Rgds



 
Wednesday, 14 June 2017 05:34 UTC
system
This ticket has been automatically closed. All tickets which have been inactive for a long time are automatically closed. If you believe that this ticket was closed in error, please contact us.
This ticket is closed, therefore read-only. You can no longer reply to it. If you need to provide more information, please open a new ticket and mention this ticket's number.