• hello there i want people to share my content to facebook and then they have access to the submit button

    this is my script it works fine in html or the w3schools testmode

    but its not working in wordpress

    this is the whole code i wrote in text mode of a page

    <!DOCTYPE html>
    <html>
    <body>

    <div id=”results”>
    <p>Download content is locked! Please share it & unlock the content</p>
    <center>
    <img onclick=”shareOnFB();” style=”cursor:pointer” src=”https://d1wofkmqsniyp0.cloudfront.net/public/v2.0/imgs/fbshare.png”&gt;
    </center>
    </div>

    <script type=”text/javascript”>
    function shareOnFB() {
    var e = {
    method: “feed”,
    link: “https://w3lessons.info&#8221;,
    picture: “https://w3lessons.info/logo_large.png&#8221;,
    name: “W3lessons – PHP, MYSQL, HTML5, CSS3, jQuery, Ajax, Facebook Style Scripts”,
    caption: ‘w3lessons.info’,
    description: “w3lessons.info is a programming blog maintained by Karthikeyan K. Tutorials focused on Programming, Jquery, Ajax, PHP,HTML5, CSS3, Web Design and MySQL”
    };
    FB.ui(e, function(t) {
    if (t[“post_id”]) {
    //your download content goes here
    // Do something there
    var secret_data = “<h2 class=\”stitle1\”>Thank you!</h2><h2 class=\”stitle2\”>Please use the below link to download</h2><p class=\”d_link\”>https://app.box.com/s/j23e7gxuug2ml54m09d4</p>”;
    jQuery(“#results”).html(secret_data);
    }
    })
    }

    </script>

    <div id=”fb-root”></div>

    <script>(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = “//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=843374912383596&version=v2.0”;
    fjs.parentNode.insertBefore(js, fjs);
    }(document, ‘script’, ‘facebook-jssdk’));</script>

    </body>
    </html>

    any help would be appreciated please please please help

Viewing 2 replies - 1 through 2 (of 2 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I don’t think people are going to help from that code. If you linked to the Webpage with the problem then that will be much more appealing.

    Did you place this entire bloc of code in the post editor text mode? that wouldn’t help, actually setting up a custom template would help, OR enqueueing that JS when the user is viewing that post or page you are working on, something like:

    add_action('wp_head', 'enqueue_my_js');
    
    function enqueue_my_js() {
    	if( is_page( array( 1 ) ) ) {
    		?>
    		<script>
    		Js goes here
    		</script>
    		<?php
    	}
    }

    To be added in the end of your functions.php file, make sure you add the post/page ID in the 4th line instead of 1 ( e.g is_page( array( 15 ) ) )

    Let us know how it goes.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘how to use javascript on wordpress’ is closed to new replies.