• Hi,

    Having a bit of an issue displaying some code in any widget,
    I have tried custom html widget text widget, siteorigin editor,
    And none of them will display the content of my code.

    The thing is I have some widgets displaying the code correctly,
    But if I edit and save them again, the code doesn’t display the content correctly.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    What do you mean by “display my code”?

    Thread Starter EMar

    (@sounds)

    Sorry I should have explained better,

    I’m using an app I bought on CodeCanyon that displays a block for shoutcast now playing
    info and last tracks played, usually I would copy a piece of code into a sidebar widget
    and it would display the app on my sidebar, which has worked on and off, always have
    issues with text widgets displaying it, but it was working.

    I then edited some text and saved the widget again, the code is still intact but it’s
    not displaying the app in the sidebar.

    This is the app I use link

    Usually I just embed this snippet of code and it displays in the sidebar text widget.

    With this:

    <!--start shoutcast style-->
    <link rel="stylesheet" type="text/css" href="https://site.com/shoutcastinfo-ambient/css/darkVertical.css" media="screen" /><!--shoutcast info style-->
    <link href="https://www.site.com/shoutcastinfo-ambient/player/clean.css" rel="stylesheet" type="text/css" /><!--player style-->
    <link href="https://www.netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
    <link href='https://www.fonts.googleapis.com/css?family=Open+Sans:400,300,700&subset=latin,greek,vietnamese,cyrillic' rel='stylesheet' type='text/css'>
    <!--end shoutcast style-->
    
    <!--start javascripts/css - WARNING!! if you have already the jQuery libraries in your page or Fancybox you must remove these lines from here!!-->
    <link rel="stylesheet" type="text/css" href="https://www.site.com/shoutcastinfo-ambient/js/fancybox/jquery.fancybox-1.3.0.css" media="screen" />
    <script type="text/javascript" src="https://www.site.com/shoutcastinfo-ambient/js/fancybox/jquery.fancybox-1.3.0.pack.js"></script>
    <script src="https://www.site.com/shoutcastinfo-ambient/js/simple-slider.min.js"></script> 
    <!--end javascripts/css-->
    
    <!--start shoutcast javascripts-->
    <script>
    //settings
    var websiteUrl = 'https://www.site.com/shoutcastinfo-ambient/';//website url
    var showPlayer = '0';//show player status
    var shoutcastUrl = '198.24.145.147:9332';//shoutcast stream server url
    var autostartPlayer = false;//autostart player status
    var displayPlayer = 'top';//player area
    </script>
    <script type="text/javascript" src="https://www.site.com/shoutcastinfo-ambient/js/main.js"></script>
    <!--end shoutcast javascripts-->
    
    <!--SHOUTCAST INFO AND STATS START - Add this in your page(s)-->
    <div id="statsOuter">
    <div id='playNow'>
    <!--show Shoutcast info and stats here-->
    </div>
    <div id='hiddeNowPlay'>
    <!--hidden title-->
    </div>
    </div>
    <!--SHOUTCAST INFO AND STATS END-->
    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    You can’t throw stuff like that into a text or HTML widget. You’re going to have to do some coding to properly queue the javascript and stylesheets. It might be easier to look for a shoutcast plugin.

    Please note that codecanyon is a commercial site and commercial products are not supported in these forums. .

    Thread Starter EMar

    (@sounds)

    It worked fine until I edited and saved the widget, so something has changed.
    I thought there might be a widget editor for displaying javascript and other code.
    I have this same code for 22 radio pages, so I can’t touch any of them right now.

    The custom html widget allows you to add some custom html, but what you are looking to enter MUST be coded into the theme the proper way for it to work.

    Everything that starts with <link or <script
    must be enqueued in the theme’s functions.php or coded into the header/footer of the template page.

    Thread Starter EMar

    (@sounds)

    Would creating a custom plugin work, then add it as a widget?
    I was reading up on that last night but my code was rejected each
    time because of some errors in my javascript code.
    I need to reuse this script for different pages, sidebar widget.
    But each page has different now playing song info so the code
    would have different settings in each widget.

    Thread Starter EMar

    (@sounds)

    I think I found a solution but don’t know if i’s the best one.
    I installed PHP Code Widget and pasted the php file into the widget text area.

    That is a workaround but not a secure solution.

    I assume you have a bit of coding skills.. I would create an include for the functions.php file and write a conditional enqueue function for the scripts and css for the app. Then create a custom app.php file that included the html and js for the app. Then use get_template_part( includes’, ‘app’ ); to include it in the theme template for all the “radio” pages that need it.

    Thread Starter EMar

    (@sounds)

    There is a php file for displaying the app.
    That’s what I pasted into the PHP Code widget.
    This is how it looks in the theme sidebar area.

    Actually I’m using a shorter version of the above document for the widget area.

    I’m not sure how to include each file in functions.php

    I see this enqueue function in my functions.php

    /**
     * Enqueue the css and js files in child theme
     *
     */
    
    function child_enqueue_scripts( $file_dir,$file_url ){
    	$child_style = str_replace( get_template_directory(),get_stylesheet_directory(),$file_dir);
    	if(file_exists($child_style)){
    		return str_replace( get_template_directory_uri(),get_stylesheet_directory_uri(),$file_url);
    	}else{
    		return $file_url;
    	}
    }
    • This reply was modified 8 years, 3 months ago by EMar.

    so you are using a child theme?
    in your child theme’s functions.php
    add require_once('includes/app-functions.php');
    create a folder named “includes” and a file named “app-functions.php”

    in that file:

    
    <?php
    
    //enqueue app scripts and styles
    <?php 
    function the_app_scripts_styles() {
     
       // Loads shoutcast CSS file.
      wp_enqueue_style('shoutcast-theme', 'https://site.com/shoutcastinfo-ambient/css/darkVertical.css', false ,'');
      // Loads player CSS file.
      wp_enqueue_style('player-css', 'https://www.site.com/shoutcastinfo-ambient/player/clean.css', false ,'');
      // Loads FontAwesome CSS file.
      wp_enqueue_style('fontawesome-css', 'https://www.netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css', false ,'');
      // Loads google fonts CSS file.
      wp_enqueue_style('fonts-css', 'https://www.fonts.googleapis.com/css?family=Open+Sans:400,300,700&subset=latin,greek,vietnamese,cyrillic', false ,'');
      // Loads fancybox CSS file.
      wp_enqueue_style('fancybox-css', 'https://www.site.com/shoutcastinfo-ambient/js/fancybox/jquery.fancybox-1.3.0.css', false ,'');
     
      // Loads app JavaScript files.
      wp_enqueue_script('fancyboxJS', 'https://www.site.com/shoutcastinfo-ambient/js/fancybox/jquery.fancybox-1.3.0.pack.js', array('jquery'),'0', true );
      // Loads shoutcast main JavaScript files.
      wp_enqueue_script('shoutMain', 'https://www.site.com/shoutcastinfo-ambient/js/main.js', array('jquery'),'0', true );
    
    }
    add_action('wp_enqueue_scripts', 'the_app_scripts_styles');
    
    

    then create a file in the child-theme folder named app.php

    
    <? php
    
    <!--start shoutcast javascripts-->
    <script>
    //settings
    var websiteUrl = 'https://www.site.com/shoutcastinfo-ambient/';//website url
    var showPlayer = '0';//show player status
    var shoutcastUrl = '198.24.145.147:9332';//shoutcast stream server url
    var autostartPlayer = false;//autostart player status
    var displayPlayer = 'top';//player area
    </script>
    <!--end shoutcast javascripts-->
    
    <!--SHOUTCAST INFO AND STATS START - Add this in your page(s)-->
    <div id="statsOuter">
    <div id='playNow'>
    <!--show Shoutcast info and stats here-->
    </div>
    <div id='hiddeNowPlay'>
    <!--hidden title-->
    </div>
    </div>
    <!--SHOUTCAST INFO AND STATS END-->
    

    make a duplicate of the page template that the radio pages are using and at the top add this or change what is there to this:

    
    <?php
    /* Template Name: Radio-APP-Page
    *
    */
    

    somewhere in the page it will call the sidebar <?php get_sidebar();?>
    if you add this get_template_part( ‘app’ );

    go to the radio pages and select Radio-APP-Page as the page template and it will shot the app in the template –

    Thread Starter EMar

    (@sounds)

    Sorry I lost you on the last bit, <?php get_sidebar();?>
    I want to display it in a widget area not replace the sidebar.

    <?php get_sidebar(name);?> is how you show a custom widget. Not the “Sidebar” it is just WordPress’ name for a widgetized section.

    https://codex.wordpress.org/Widgetizing_Themes

    Thread Starter EMar

    (@sounds)

    Thanks Hudson for the info, I didn’t know about that, I’ll get on it.

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Can’t display my code in any widget’ is closed to new replies.