Pugpig Hooks

Pugpig has many hooks that you can use to modify and improve your app. Pugpig will apply these filters automatically. To learn more about adding hooks for Pugpig in WordPress see WordPress Filters Explained.

  • OPDS
  • Edition Atom
  • Manifest
  • Pugpig Products

Pugpig WordPress Connector v2.0.0+ has a Pugpig Hooks extension with all the hooks listed below. Activating this extension will enable the hooks and you should be able to view the changes in the OPDS feed, atom feeds, manifests and product jsons.



This hook allows modules to decide if we should keep the edition in the OPDS feed. Return a boolean in your filter. True, the default, will keep the edition in the feed.

add_filter('pugpig_keep_edition_in_feed', 'customapp_pugpig_keep_edition_in_feed', 10, 2);
function customapp_pugpig_keep_edition_in_feed($keep, $edition) {
if ($edition == 'test'){
return false;

return true;


This hook allows modules to add custom categories to the OPDS feed. In the example below we are defining the pane_model as horizontal.

add_filter('pugpig_add_opds_custom_categories', 'customapp_pugpig_get_edition_opds_custom_categories', 10, 2);
function customapp_pugpig_get_edition_opds_custom_categories ($custom_categories, $edition) {
$custom_categories['pane_model'] = 'horizontal';

return $custom_categories;


For information on edition atom feeds and how to customise them please see here.


This hook adds a sharing link to the edition atom feed. By default sharing is enabled and clicking the share button in the app will share a permalink to the page. Return:

  • null to disable individual page sharing
  • an external url to link to that  
  • '  ' (whitespace) to share an image such as a screenshot.

If individual page sharing is disabled you can set an edition sharing link in the Edition Edit Page. If you return a space you need to define elsewhere in the sharing_mode. See pugpig_feed_post_custom_categories below.

add_filter('pugpig_page_sharing_link', 'customapp_page_sharing_link', 10, 2);
function customapp_page_sharing_link($link, $post) {
$updated_link = get_post_meta($post->ID, 'pugpig_sharing_url', true);
if($updated_link) {
return $updated_link;


This hook changes the id of a post. This might be useful if you want to remap the ids or incorporate posts from multiple sources.

add_filter('pugpig_feed_post_id', 'customapp_feed_post_id', 10, 2);
function customapp_feed_post_id($post_id, $post) {
if (!in_array($post_id, $some_array_of_ids)){
$post_id = (count($some_array_of_ids)+1);

return $post_id;


This hook allows you to change the title of a post.

add_filter('pugpig_feed_post_title', 'customapp_feed_post_title', 10, 2);
function customapp_feed_post_title ($summary, $post) {
$title = 'NEWS';

return $title;


This hook allows you to change the level of a post. Posts are level 1 by default.

add_filter('pugpig_feed_post_level', 'customapp_feed_post_level', 10, 2);
function customapp_feed_post_level ($summary, $post) {
$level = get_post_meta($post->id, 'Pugpig_article_level');

return $level;


This hook allows you to change the author of a post. By default this is the WordPress users display name.

add_filter('pugpig_feed_post_author', 'customapp_feed_post_author', 10, 2);
function customapp_feed_post_author ($summary, $post) {
$author = 'Kaldor';

return $author;


This hook changes the summary text in the edition atom feed. The summary text by default takes it's value from the custom field post_excerpt. If this field does not exist or if you want to overwrite it you can use this hook. In this case the summary is shorten to 40 character however you could just replace the summary.

add_filter('pugpig_feed_post_summary', 'customapp_feed_post_summary', 10, 2);
function customapp_feed_post_summary($summary, $post) {
$length = strlen($summary);
$short_summary = substr($summary, 0, 40);
if ($length > 40) {
$short_summary .= " [...]";
return $short_summary;


This hook adds sections in the atom feed. Sections are used, among other things, for define sections in the Table of Contents in your app. If you want to hide ads you should return an empty section. In the example below the section name is taken from the custom_section field.

add_filter('pugpig_feed_post_categories', 'customapp_pugpig_feed_post_categories', 10, 2);
function customapp_pugpig_feed_post_categories($category, $post) {
$section = get_post_meta($post->ID, 'custom_section');
if (!empty($section)) {
$section = $section[0];
$section = ucfirst($section);
return array($section);

return array("");


This hook adds custom categories in the atom feed. Custom categories can be used for tags, setting options (see our API Spec) and other custom needs in your app. If you want to hide ads you should return an empty section. In the example below sharing_mode is set to screenshot and pane_model is set to horizontal.

add_filter('pugpig_feed_post_custom_categories', 'customapp_pugpig_feed_post_custom_categories', 10, 2);
function customapp_pugpig_feed_post_custom_categories($custom_categories, $post) {

$custom_categories['sharing_mode'] = 'screenshot';
$custom_categories['pane_model'] = 'horizontal';

return $custom_categories;


This hook adds links to specific files into the atom feed.

add_filter('pugpig_add_link_items', 'customapp_extension_add_link', 10, 2); 
function customapp_extension_add_link($links, $post) {
$slug = pugpig_get_first_category_slug($post);
if ($slug == "biology") {
$permalink = get_permalink($post->ID);
$links[] = array(
'rel' => 'bookmark',
'type' => 'text/html',
'title' => 'My Magazine',
'href' => pugpig_strip_domain($permalink)

return $links;


For information on Pugpig manifests and how to customise them please see here.


This hook adds extra items to the manifest. In the example below an image taken from the pugpig_background_image field is added. Note: $output is added to not replaced.

add_filter('pugpig_extra_manifest_items', 'customapp_pugpig_extra_manifest_items',10,2);
function customapp_pugpig_extra_manifest_items($output, $post) {

$output .= pugpig_get_custom_field_manifest_item($post, 'pugpig_background_image');

return $output;


This hook allows you to add attachments to the manifest. You should add a string will a link to the attachment, for example /wp-content/uploads/... Note: $attachments is added to not replaced.

add_filter('pugpig_attachment_manifest_items', 'customapp_pugpig_attachment_manifest_items', 10, 2);
function customapp_pugpig_attachment_manifest_items ($attachments, $post) {
$attachments .= pugpig_get_custom_attachment($post);

return $attachments;


This hook allows you to manipulate the manifest after it has been generated. In the example below we remove theme files/items from the manifest. This is very useful to reduce the size of a packaged edition. In the example below style.css, screenshot.png, fonts, views (mustache) and child themes are all removed from the manifest.

add_filter('pugpig_theme_manifest_items', 'customapp_pugpig_ignore_theme_manifest_items',10,2);
function customapp_pugpig_ignore_theme_manifest_items($output, $post) {

$output_lines = explode("\n", $output);
$output_lines = array_map(function ($item) {
// see
if (preg_match('!\/wp-content\/themes\/.*\/(?:style\.css|screenshot\.png|styles\/style-guide\.css|(?:views|fonts|wordpress-child-themes)\/)!', $item)) {
$item = '';

return $item;
}, $output_lines);

return implode("\n", array_filter($output_lines));


Pugpig has a products extension plugin that come with the core app.


This hook provides a list of product SKUs - comma separate values - to the Pugpig Products plugin. Pugpig Products will take this list and open the shopping modal when you click on a relevant image/html tag.

add_filter('pugpig_products_csv_fields', 'customapp_pugpig_products_csv_fields',10,1);
function customapp_pugpig_products_csv_fields($csv_product_fields) {

$products = array("pugpig_main_image_products");

return $products;


This hook adds to or creates the list of product SKUs created above. This hook should be used from repeater fields, such as grid items or other inline items. Pugpig Products will take this list and open the shopping modal when you click on a relevant image/html tag.

add_filter('pugpig_products_csv_repeater_fields', 'customapp_pugpig_products_csv_repeater_fields',10,1);
function customapp_pugpig_products_csv_repeater_fields ($csv_product_repeater_fields) {

$more_products = array("pugpiggriditem");
return $more_products;


This hook is for manipulating product data. In the example below the hook is for adding a http query on to the end of a product sharing link. The http query is set in a settings menu. This may be required for analytical reasons.

add_filter('pugpig_product_data', 'customapp_pugpig_product_query_sharing_link', 10, 2);
function customapp_pugpig_product_query_sharing_link($product_data) {
$options = _pugpig_customapp_get_options();

if ($product_data["link"] !== ''){
$product_data["link"] = $product_data["link"] . $options['handbook']['pugpig_customapp_products_query_sharing_link'];

return $product_data;
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Powered by Zendesk