Oxygen Template Condition in Scripts Organizer

cmsexpertss
cmsexpertss
27 Oct 2023

One of our customer requested a code snippet to write a function which will check that if current post or page has a specific Oxygen template assigned.

Note: This code snippet is only for checking the template on single post/cpt or page.

<?php
function dplugins_check_oxygen_template($template = "", $post_id = 0){
    if($post_id < 1){
        return false;
    }
    $post_id = get_queried_object_id();
    
    // oxygen version less than 4.8.3
    $ct_other_template = get_post_meta( $post_id, 'ct_other_template', true );
    
    // oxygen version 4.8.3 and above
    $ct_other_template = oxy_get_post_meta( $post_id, 'ct_other_template', true );

    if($template == $ct_other_template){
        return true;
    }
    return false;
}
?>

Write this function as shown in the screenshot.

Then paste this code in “Custom” condition of the code block which you want to apply on specific posts/cpt or page with Oxygen template.

dplugins_check_oxygen_template(659, get_queried_object_id()) // where 659 is template id, and get_queried_object_id() will be used to check currently viewed post or page.

Was this article helpful?

Tags

Categories

Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy