更改插件快捷码功能

时间:2015-06-27 作者:Amro Shalaby

我使用plugin 包含此代码的,我想更改css和js以及模板。php位置位于我的模板目录中,而不是插件中,无需编辑插件文件

public function shortcode($atts, $content = NULL) {

    global $post, $wpdb;

    STATIC $i = 1;



    $timelinr_options = get_option(\'timelinr_general_options\');

    $desing_options = get_option(\'timelinr_desing_options\');

    $pairs = array(

            \'orientation\' => $timelinr_options[\'orientation\'],

            \'startat\' => intval($timelinr_options[\'startat\']),

            \'arrowkeys\' => $timelinr_options[\'arrowkeys\'],

            \'autoplay\' => $timelinr_options[\'autoplay\'],

            \'autoplaydirection\' => $timelinr_options[\'autoplaydirection\'],

            \'autoplaypause\' => $timelinr_options[\'autoplaypause\'],

            \'order\' => $timelinr_options[\'order\'],

            \'containerdiv\' => \'timelinr-\'.$i,

            \'category\' => \'\',

            \'dateformat\' => $desing_options[\'dateformat\'],

    );

    $atts = shortcode_atts($pairs, $atts );



    if ( strcmp ( $atts[\'orientation\'] , \'horizontal\' ) == 0){

        wp_enqueue_style(\'timelinr-style\', JQTL_BASE_URL . \'/assets/css/style.css\', \'\', JQTL_CURRENT_VERSION );

    } elseif ( strcmp ( $atts[\'orientation\'] , \'vertical\' ) == 0) {

        wp_enqueue_style(\'timelinr-style_v\', JQTL_BASE_URL . \'/assets/css/style_v.css\', \'\', JQTL_CURRENT_VERSION );

    }



    ob_start();

    include (JQTL_BASE_PATH . \'/includes/template.php\');

    $out = ob_get_contents();

    ob_end_clean();



    $i++;

    return $out;

}

1 个回复
最合适的回答,由SO网友:mmm 整理而成

您可以像这样覆盖短代码:

add_action("init", function () {


    remove_shortcode("timelinr");

    add_shortcode("timelinr", function ($atts, $content) {

        // call the shortcode of jqueryTimelinrLoad
        $result = $GLOBALS["jqueryTimelinrLoad"]->shortcode($atts, $content);

        // dequeue style
        wp_dequeue_style("timelinr-style");

        // enqueue your style
        wp_enqueue_style("timelinr-style2", "new.css");

        // result of the shortcode
        return $result;
    });

});

结束

相关推荐

Virtual Pages plugins

我很难让插件正常工作Virtual Pages (WordPress插件可简化虚拟页面的创建)我确实进行了编辑,根据查询创建了一个循环。add_action( \'gm_virtual_pages\', function( $controller ) { /* Creating virtuals pages for companies */ $args = array( \'post_type\' => array(\'companies\',), \'post_status\'