• I’m trying to add shortcodes for my adsense ads and am experiencing problems. Here is the code that I am adding to the functions.php of my Child Theme.

    function google_adsense1() {
        return '<script type="text/javascript"><!--
    google_ad_client = "<em>your client id</em>";
    google_ad_slot = "<em>your ad slot id</em>";
    google_ad_width = <em>width</em>;
    google_ad_height = <em>height</em>;
    //-->
    </script>
    <script type="text/javascript"
    src="https://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    ';
    }  
    
    add_shortcode('adsense1', 'google_adsense1');

    Of course I am replacing what I need to with my ads information. When I add the [adsense1] to the text view of my page and update, the screen goes white. Normal functioning of my dashboard will not resume until I delete the functions.php on the remote server.

    What am I doing wrong here?

    Thanks!
    Corey

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter shootingtime

    (@shootingtime)

    I am using the Expound theme and my url is https://shootingtime.com

    That is not the way to handle a script in WordPress. You should be using wp_enqueue_script() with the $in_footer parameter.

    Thread Starter shootingtime

    (@shootingtime)

    I’ll look into that. Thanks.

    Thread Starter shootingtime

    (@shootingtime)

    I will place a shortcode in my pages where necessary. Could you give me an example of what the finished functions.php code should look like? The page you linked looks a little complicated for me. I of course will continue to research.

    This looks a little contradictory.

    $in_footer
    (boolean) (optional) Normally, scripts are placed in <head> of the HTML document. If this parameter is true, the script is placed before the </body> end tag. This requires the theme to have the wp_footer() template tag in the appropriate place.
    Default: false

    This looks a little contradictory.

    Sorry? What part are you having a problem with?

    Thread Starter shootingtime

    (@shootingtime)

    I just got confused with it saying the scripts are placed in the head.

    Esmi, prior to September 27th, I thought wordpress was a place that made newspapers, lol. I understand quite a bit now but am trying to figure out how I can implement adsense shortcode successfully without a plugin.

    I understand the suggested method you provided will probably work, but I lack the knowledge to understand how. From what I know, all I would have to do is add the proper coding to the functions.php of my child theme. I attempted that after some research and came up with the error.

    Is there a way you could spoon feed me how I should do it? I installed a shortcode plugin which works. I then looked through the files on the server for how they coded it, but couldn’t find it.

    Thanks for your help esmi.

    Corey

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Problems with adding shortcode’ is closed to new replies.