Creating a Pinterest widget for site

Hi,

I am trying to create a Pinterest widget and embed it into a certain page on my site. I have found this page;

https://developers.pinterest.com/tools/widget-builder/?type=board&boardHeight=240&boardWidth=400&imageWidth=80&template=square&url=https%3A%2F%2Fwww.pinterest.co.uk%2Fjonathan8729%2Finspiration%2Fbeds%2F

It says that I need to copy the code into my page, which I have done via adding a raw content element and adding the code into it. It also says that I need to include the pinit.js once per page, right before the closing tag. I have added the code given to the content JS and clicked run but nothing happens.

Could someone give me a hand with getting this working?

I will add the draft page I am working on and login details to a secure message

Pix.

Hi Mark,

Thanks for reaching out.

The content <a data-pin-do="embedBoard" data-pin-board-width="400" data-pin-scale-height="240" data-pin-scale-width="80" href="https://www.pinterest.co.uk/jonathan8729/inspiration/beds/"></a> should be added to raw or text element. While this should be added to child theme’s functions.php

add_action('wp_footer', 'pinterest_widget', 999999999);

function pinterest_widget() { ?>

<script async defer src="//assets.pinterest.com/js/pinit.js"></script>

<?php }

Thanks!

Tried adding the code to the functions.php and get the following error;

Your PHP code changes were rolled back due to an error on line 7 of file wp-content/themes/x-child-integrity-light/functions.php. Please fix and try saving again.
syntax error, unexpected ‘}’, expecting end of file

Also was thinking that by adding the code to load the script that way would mean that it would load on every page, affecting site performance. Is there a way that I can add it just to that page, rather than the whole site?

Hi Pix,

Please try the code:

add_action('wp_footer', 'pinterest_widget');

function pinterest_widget(){
    if(is_page( '100' ) ) :
?>
        <script async defer src="//assets.pinterest.com/js/pinit.js"></script>
<?php
    endif;
};

Please change the 100 page ID in the code. To locate the page/post ID, please check here:

Hope this helps.

Hi,

Thanks that looks a better solution. I have found my page number and entered it, but I still get an error. I am trying to add this to the functions.php of my child theme via appearance>editor. Also, I noticed that this code mentions the wp-footer, it is asked that this script be placed just before the /body tag.

Your PHP code changes were rolled back due to an error on line 8 of file wp-content/themes/x-child-integrity-light/functions.php. Please fix and try saving again.
syntax error, unexpected ‘endif’ (T_ENDIF), expecting end of file

This is what I was trying to enter;

add_action('wp_footer', 'pinterest_widget');

function pinterest_widget(){
    if(is_page( '3669' ) ) :
?>
        <script async defer src="//assets.pinterest.com/js/pinit.js"></script>
<?php
    endif;
};

Hi there.

Try to login through FTP then go to wp-content/themes/x-child then add the code in the functions.php file.

Hope this helps.

Hi Jade,

I tried that but when I then go to visit the site I see this;

So I have switched back to the empty functions.php I had for now.

Please note that this code needs to be added just before the closing /body tag.

Hi there,

It looks like you are still using an older version of the child theme.

Can you try downloading the child theme here and install it on the site and move all the customization to the new child theme.

https://theme.co/apex/child-themes

Hope this helps.

Hi Jade,

That has sorted my issue, widget now displaying.

Thanks for your help. :slight_smile:

Kind regards,

Mark

You’re most welcome!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.