By Afshin


2019-11-08 12:42:56 8 Comments

This is my jQuery code:

$(document).ready(function () {
    var mediaUploader;
    $("#upload-button").on("click", function (e) {
        e.preventDefault();
        if (mediaUploader) {
            mediaUploader.open();
            return;
        }

        mediaUploader = wp.media.frames.file_frame = wp.media({
            title: 'Choose ...',
            button: {
                text: 'banner'
            },
            multiple: false
        });

         mediaUploader.on("select", function () {
             attachment = mediaUploader.state().get("selection").first().toJSON();
             $("#pageBannerBackground").val(attachment.url);
         });
         mediaUploader.open();
    });
});

This is the PHP code I wrote. When I choose the photo and crop it, the output is not what I cropped and is the main photo.

    function mehrAmoz_page_banner_background() {
    $pageBannerBackground = esc_attr(get_option('pageBannerBackground'));
    echo "<h3 class=' btn btn--blue'>Background</h3>";
    echo "<div><input class='btn btn--small btn--beige' type='button' value='upload' id='upload-button'><input type='hidden' name='pageBannerBackground' id='pageBannerBackground' value='{$pageBannerBackground}'></div>";
    echo "<img class='homepageBanner' src='{$pageBannerBackground}'>";
}

0 comments

Related Questions

Sponsored Content

1 Answered Questions

1 Answered Questions

WordPress Theme backend admin panel section feature image doesn't appear?

  • 2017-02-08 05:45:56
  • rajinder
  • 39 View
  • 1 Score
  • 1 Answer
  • Tags:   php wordpress

2 Answered Questions

How to Hide / Show Wordpress Admin Bar from Theme Settings Panel

  • 2016-04-27 08:36:28
  • user5247236
  • 561 View
  • 0 Score
  • 2 Answer
  • Tags:   php wordpress

1 Answered Questions

WordPress Admin panel showing code

  • 2015-12-01 15:27:55
  • hetal gokani
  • 129 View
  • 0 Score
  • 1 Answer
  • Tags:   wordpress

2 Answered Questions

[SOLVED] Java Script Create Unique Class For Each Image

  • 2015-01-12 11:05:50
  • Mr. ED
  • 202 View
  • 0 Score
  • 2 Answer
  • Tags:   javascript jquery

1 Answered Questions

ASP.NET MVC Jquery send image to action for upload

1 Answered Questions

Javascript create a new upload image form on click

1 Answered Questions

2 Answered Questions

[SOLVED] Wordpress admin panel theme

Sponsored Content