Smart Post Show Pro

  1. Home
  2. Docs
  3. Smart Post Show Pro
  4. Hooks: Actions and Filters

Hooks: Actions and Filters

A comprehensive guideline on how to use Smart Post Show Pro filter and action hooks. We have added the following hooks for developers to extend functionalities. Simply add the following custom code to your current theme’s functions.php file. It’s recommended to keep the code in the functions.php file of your child theme. Because you might lose your customizations if the theme is updated. Keeping the modified codes in your parent theme’s child theme is therefore the best practice.

1) How to change the plugin name

2) How to grant plugin access to editors

3) How can the plugin be made visible to the authors

4) How to change the plugin’s default placeholder image

5) How to change the default Sale text

6) How to add subtitles below the section title

7) How to add custom fonts in the plugin

 

1) How to change the plugin name

If you want to change the Smart Post Show Pro plugin name for any reason, you can easily do it with the following custom code. If you check the code, you will see there is a filter hook (sp_post_carousel_post_type_labels) available in the plugin by which you can make the modification.

add_filter( 'sp_post_carousel_post_type_labels', 'sp_show_change_menu_name' );
/**
 * Change plugin menu name.
 *
 * @param array $labels The labels.
 * @return string
 */
function sp_show_change_menu_name( $labels ) {
    unset( $labels['menu_name'] );
    $new_menu_name = array( 'menu_name' => __( 'My Plugin', 'smart-post-show' ) );
    return array_merge( $new_menu_name, $labels );
}

2) How to grant plugin access to editors

If you want to give the plugin access to the editors, you can do it easily with the help of the following custom code. If you check the code, you will see there is a filter hook (sp_pc_dashboard_capability) available in the plugin which allows you to modify the plugin’s functionality.

// Plugin visible to editor
add_filter( 'pcp_user_role_permission', 'pcp_user_role_permissionto_editor' );
function pcp_user_role_permissionto_editor() {
    return 'edit_pages';
}

3) How can the plugin be made visible to the authors?

If you want to make the plugin visible to the authors, you can do it easily with the help of the following custom code. If you check the code, you will see there is a filter hook (pcp_user_role_permission) available in the plugin which allows you to modify the plugin’s functionality.

// Plugin visible to author
add_filter( 'pcp_user_role_permission', 'sp_pc_dashboard_capability_to_author' );
function sp_pc_dashboard_capability_to_author() {
    return 'edit_posts';
}

4) How to change the plugin’s default placeholder image

If you want to change the default placeholder image of the plugin, you can do it easily with the help of the following custom code. If you check the code, you will see there is a filter hook (pcp_no_thumb_placeholder) available in the plugin which allows you to modify the plugin’s functionality.

// Placeholder image customized
add_filter( 'pcp_no_thumb_placeholder', 'pcp_no_thumb_placeholder_modified' );
function pcp_no_thumb_placeholder_modified($placeholder_img){
// Your custom placeholder image url uploaded to your website media.
$placeholder_img = 'http://smart-post-show-pro.local/wp-content/uploads/2021/12/2c48913c-4893-36b3-bad6-999b255fe22b.jpg';
    return $placeholder_img;
}

5) How to change the default Sale text

If you want to change the Sale text for all of your products when you are showing a product carousel/grid you can do it easily with the following custom code. If you check the code, you will see there is a filter hook (sp_pcp_woocommerce_sale_text) available in the plugin which allows you to modify the plugin’s functionality.

// Change the Sale text for all products
add_filter( 'sp_pcp_woocommerce_sale_text', 'sp_pcp_woocommerce_sale_text_modified' );
function sp_pcp_woocommerce_sale_text_modified(){
    return __( 'On Sale', 'smart-post-show-pro' );
}

6) How to add subtitles below the section title

If you want to add a subtitle below the section title you can easily do it with the following custom code. If you check the code, you will see there is a filter hook (pcp_after_section_title) available in the plugin which allows you to modify the plugin’s functionality.

// Subtitle after the section title
add_action( 'pcp_after_section_title', 'pcp_after_section_subtitle', 10 );
function pcp_after_section_subtitle(){
?>
<p class="pcp-section-sub-title">
Praesent sapien massa, convallis a pellentesque nec.
<?php
}

7) How to add custom fonts in the plugin

If you want to add any custom font to the plugin. You can do this easily with the custom code below. But your custom font must be enqueued/loaded in your theme or site. Then you just need to write the font name in the function below. If you check the code you will see there is a filter hook available (spf_field_typography_customwebfonts) in the plugin by which you can easily add custom fonts.

if( ! function_exists('spf_field_typography_customwebfonts')) {
    function spf_field_typography_customwebfonts_modified() {
        // your custom fonts 
        $custom_fonts = array(
            'VTF Redzone Classic',
            'SP Jupiter',
        );
        return $custom_fonts;
    }
}
add_filter( 'spf_field_typography_customwebfonts', 'spf_field_typography_customwebfonts_modified' );