• Resolved Sarah Haruel

    (@sarah-haruel)


    Great plugin that is so close to solving a massive problem for me

    Hopefully this is an easy question that someone may be able to answer ?

    Using this plugin, is it possible to have the output as

    <script type=’application/ld+json’id=”sns_scripts_in_head”>

    instead of

    <script type=”text/javascript” id=”sns_scripts_in_head”>

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Sarah Haruel

    (@sarah-haruel)

    I am trying to enter son schema but the app is changing the code negatively

    Help !

    Thread Starter Sarah Haruel

    (@sarah-haruel)

    I think I cobbled together a crude fix.

    Im sure this was not the correct way to do things but if the developer ever checks these pages then by all means if you have the time to assist / implement this as a proper fix so its plugin upgrade survivable ?

    Obviously if you were able to implement it into the plugin, then would be good to ensure the plugin preserves any <script type=’application/ld+json’id=”sns_scripts_in_head”> code that has been added into a post.

    /**
    * Theme Action: ‘wp_footer()’
    * Outputs the globally and individually set Scripts at the end of the Theme’s body element.
    */
    static function scripts() {
    // Global
    $options = get_option( ‘SnS_options’ );
    if ( ! empty( $options ) && ! empty( $options[ ‘scripts’ ] ) ) {
    ?><script type=”application/ld+json’id” id=”sns_global_scripts”><?php
    echo $options[ ‘scripts’ ];
    ?></script><?php
    }
    if ( ! empty( $options ) && ! empty( $options[ ‘coffee_compiled’ ] ) ) {
    ?><script type=”application/ld+json’id” id=”sns_global_coffee_compiled”><?php
    echo $options[ ‘coffee_compiled’ ];
    ?></script><?php
    }

    if ( ! is_singular() ) return;
    // Individual
    global $post;
    $SnS = get_post_meta( $post->ID, ‘_SnS’, true );
    $scripts = isset( $SnS[‘scripts’] ) ? $SnS[ ‘scripts’ ]: array();
    if ( ! empty( $scripts ) && ! empty( $scripts[ ‘scripts’ ] ) ) {
    ?><script type=”application/ld+json’id” id=”sns_scripts”><?php
    echo $scripts[ ‘scripts’ ];
    ?></script><?php
    }
    }

    /**
    * Theme Action: ‘wp_head()’
    * Outputs the globally and individually set Scripts in the Theme’s head element.
    */
    static function scripts_in_head() {
    // Global
    $options = get_option( ‘SnS_options’ );
    if ( ! empty( $options ) && ! empty( $options[ ‘scripts_in_head’ ] ) ) {
    ?><script type=”application/ld+json’id” id=”sns_global_scripts_in_head”><?php
    echo $options[ ‘scripts_in_head’ ];
    ?></script><?php
    }

    if ( ! is_singular() ) return;
    // Individual
    global $post;
    $SnS = get_post_meta( $post->ID, ‘_SnS’, true );
    $scripts = isset( $SnS[‘scripts’] ) ? $SnS[ ‘scripts’ ]: array();
    if ( ! empty( $scripts ) && ! empty( $scripts[ ‘scripts_in_head’ ] ) ) {
    ?><script type=”application/ld+json’id” id=”sns_scripts_in_head”><?php
    echo $scripts[ ‘scripts_in_head’ ];
    ?></script><?php
    }
    }

    Plugin Author WraithKenny

    (@wraithkenny)

    You don’t need to do all of that.

    1. just close the script tag,
    2. add your html,
    3. then reopen the script tag.

    
    </script>
    
    <script type="application/ld+json">
    ...
    </script>
    
    <script>
    

    This plugin wasn’t designed 8 years ago for that purpose, but to add simple scripts and simple css without having to edit the theme. If you are going through the hassle of editing the plugin, you should just add the JSON tag to the theme.

    Thread Starter Sarah Haruel

    (@sarah-haruel)

    Hi WraithKenny,

    thanks for the response.

    your plugin is still solid @ 8 years old and with that nifty little workaround it is now sitting proud.

    I was in urgent need to sort out and had to try and get a workaround and as a novice to scripts etc, i had to try and cobble something together.

    I would added the JSON to the theme but I had about 40 pages for our catering business and needed a per – post specific script for recipe pages.

    Your workaround is much more elegant then my own attempt and I appreciate you taking the time to respond to my message ;0)

    • This reply was modified 6 years, 11 months ago by Sarah Haruel.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Changing <script type="text/javascript" to <script type='application/ld+json'’ is closed to new replies.