Skip to content

Commit

Permalink
Merge pull request #2641 from QuizandSurveyMaster/CU-85zte5q3u-Preloa…
Browse files Browse the repository at this point in the history
…d-added-in-Featured-Image

add preload for featured image
  • Loading branch information
zubairraeen authored Sep 10, 2024
2 parents ceaec61 + 94857fc commit fdde6dc
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions php/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ function qsm_load_main_scripts() {
* @global obj $wp_query
*/
function qsm_generate_fb_header_metadata() {
global $mlwQuizMasterNext, $wpdb, $wp_query;
if ( isset( $_GET['result_id'] ) && '' !== $_GET['result_id'] ) {
$settings = (array) get_option( 'qmn-settings' );
$facebook_app_id = '594986844960937';
if ( isset( $settings['facebook_app_id'] ) ) {
$facebook_app_id = esc_js( $settings['facebook_app_id'] );
}
global $mlwQuizMasterNext, $wpdb, $wp_query;
$result_id = sanitize_text_field( wp_unslash( $_GET['result_id'] ) );
$results_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mlw_results WHERE unique_id = %s", $result_id ) );
if ( $results_data ) {
Expand Down Expand Up @@ -194,15 +194,20 @@ function qsm_generate_fb_header_metadata() {
$pagename = $post->post_title;
$result_id = sanitize_text_field( wp_unslash( $_GET['result_id'] ) );
?>
<meta property="og:url" content="<?php echo esc_url( $sharing_page_id ) . '?result_id=' . esc_attr( $result_id ); ?>" />
<meta property="og:type" content="article" />
<meta property="og:title" content="<?php echo esc_attr( $pagename ); ?>" />
<meta property="og:description" content="<?php echo esc_attr( $sharing ); ?>" />
<meta property="og:image" content="<?php echo esc_url( $default_fb_image ); ?>" />
<meta property="fb:app_id" content="<?php echo esc_attr( $facebook_app_id ); ?>" />
<?php
<meta property="og:url" content="<?php echo esc_url( $sharing_page_id ) . '?result_id=' . esc_attr( $result_id ); ?>" />
<meta property="og:type" content="article" />
<meta property="og:title" content="<?php echo esc_attr( $pagename ); ?>" />
<meta property="og:description" content="<?php echo esc_attr( $sharing ); ?>" />
<meta property="og:image" content="<?php echo esc_url( $default_fb_image ); ?>" />
<meta property="fb:app_id" content="<?php echo esc_attr( $facebook_app_id ); ?>" />
<?php
}
}
$quiz_id = $mlwQuizMasterNext->quizCreator->get_id();
$featured_image = get_option("quiz_featured_image_$quiz_id");
?>
<link rel="preload" href="<?php echo esc_url($featured_image); ?>" as="image">
<?php
}

add_action( 'wp_head', 'qsm_generate_fb_header_metadata' );
Expand Down

0 comments on commit fdde6dc

Please sign in to comment.