• I found a post from a few weeks ago about using custom shortcodes globally across all your multisite blogs. I was just after a bit more information.

    I’ve installed a plugin called Shortcoder, and network activated it, but shortcodes i create under super admin arent able to be used by subdomain blogs.

    Can someone give me some pointers about how to create shortcodes that i can then use across any of my blogs. I’m after adding some static content to all my sites, which i can edit centrally, and this may well be the best way to do it.

    Thanks

Viewing 1 replies (of 1 total)
  • First,

    how to create shortcodes

    Reading: https://codex.www.ads-software.com/Shortcode_API

    Multisite tip: Stick the following in your “mu-plugins” folder

    // [bartag foo="foo-value"]
    function bartag_func($atts) {
    	extract(shortcode_atts(array(
    		'foo' => 'something',
    		'bar' => 'something else',
    	), $atts));
    
    	return "foo = {$foo}";
    }
    add_shortcode('bartag', 'bartag_func');

    Then
    [bartag foo="something" bar="something else"] in any post from any site.

    Second,

    I’ve installed a plugin called Shortcoder, and network activated it, but shortcodes i create under super admin arent able to be used by subdomain blogs

    Shortcoder is going to save its array of options as blog options. Looking briefly at the Shortcoder code, it is possible to hook the option_pre filter and have the plugin retrieve options from another blog(or hard code the option array)

    Examples:
    https://www.ads-software.com/support/topic/possible-to-set-default-plugin-settings-for-every-blog
    https://www.ads-software.com/support/topic/sub-blogs-use-the-main-blog-widgets

    FInally:
    So, (net)activate and maintain Shortcoder in the usual way but put something like this in your “mu-plugins” and the options will come from what is saved on blog 1, no matter which blog uses the shortcode/plugin. (Also remove the Shortcoder menu from every blog but the main.)

    <?php
    global $blog_id;
    if($blog_id != '1') {
    	add_filter( 'pre_option_' . 'shortcoder_data', 'override_shortcoder_data' );
    	add_action( 'plugins_loaded', 'override_sc_addpage');
    
    function override_sc_addpage() {
    	remove_action( 'admin_menu', 'sc_addpage');
    }
    function override_shortcoder_data() {
    	$bar = get_blog_option('1','shortcoder_data');
    	return $bar;
    }
    }
    ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Global Shortcodes’ is closed to new replies.