• Resolved Mak

    (@makolyte)


    How can I change defaults? I saw in the documentation about adding “add_action(“init”) in functions.php, but that didn’t seem to work.

    I may just need to mod the php files in the plugin, but I’d like to avoid that since that will be more work in the future to keep it synced with the main repo.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    Default options for what?

    Did you see the documentation wiki?

    Thread Starter Mak

    (@makolyte)

    The default options in the code block. For example:
    Show line numbers=true
    Default language=C#

    I looked at the instructions for adding “add_action”. I tried sticking this in functions.php, but the code block still had the default options (i.e. show line numbers = false)

    Here’s what I tried:
    add_action(
    ‘init’,
    function() {
    $block_type = WP_Block_Type_Registry::get_instance()->get_registered( ‘core/code’ );
    $block_type->attributes[‘language’][‘default’] = ‘cs’;
    $block_type->attributes[‘showLineNumbers’][‘default’] = true;
    }
    );

    Plugin Author Weston Ruter

    (@westonruter)

    Even when you create a new Code block? I believe that doesn’t change existing blocks.

    Thread Starter Mak

    (@makolyte)

    Yes, even when I create a new Code block, it still has the defaults instead of my overrides.

    In case this is useful info:
    WP: 5.5.1
    Theme: GeneratePress 2.4.2

    Plugin Author Weston Ruter

    (@westonruter)

    It looks like you have to supply a priority greater than 100 for the init action. This ensures it runs after \Syntax_Highlighting_Code_Block\init(). I’ve updated the wiki to fix that.

    Thread Starter Mak

    (@makolyte)

    That solved it. Thanks alot!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How can I change the default options?’ is closed to new replies.