After my function.php code was modified I get a white screen when trying to go to my wordpress /wp-admin page. What could be causing the issue? Also general code improvement are welcome, as I never coded in php or wordpress before.
function.php file
<?php
function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' ),
'footer-menu1' => __( 'Footer Menu 1' ),
'footer-menu2' => __( 'Footer Menu 2' ),
'footer-menu3' => __( 'Footer Menu 3' ),
'side-menu' => __( 'Side Menu' ),
)
);
}
add_action( 'init', 'register_my_menus' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'custom-logo' );
add_filter ( 'nav_menu_css_class', 'so_37823371_menu_item_class', 10, 4 );
function so_37823371_menu_item_class ( $classes, $item, $args, $depth ){
$classes[] = 'nav-item';
return $classes;
}
add_filter( 'nav_menu_link_attributes', function($atts) {
$atts['class'] = "nav-link";
return $atts;
}, 100, 1 );
function my_theme_assets_files() {
wp_enqueue_script( 'custom-js', get_template_directory_uri(). '/js/custom.js' , [], '1.0.0' , true );
wp_localize_script( 'custom-js', 'jsh_ajax', [
'ajax_url' => admin_url( 'admin-ajax.php' )
]);
}
add_action( 'wp_enqueue_scripts', 'my_theme_assets_files' );
add_action("wp_ajax_sk_ajax_posts", "sk_ajax_posts");
add_action("wp_ajax_nopriv_sk_ajax_posts", "sk_ajax_posts");
function sk_ajax_posts() {
$cat_id = $_POST['cat_id'];
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'cat' => $cat_id ,
// 'orderby’ => 'title',
// 'order’ => 'ASC',
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
//the_post();
$categories = get_the_category();
$category_name = $categories[0]->name;
?>
<div class="col-md-4 ">
<div class="card border-0">
<div class="image-parent">
<?php echo wp_get_attachment_image( get_post_thumbnail_id( get_the_ID() ), 'full', '', [ 'class' => 'card-img-top' ] ); ?>
<?php echo $category_name; ?>
</div>
<div class="card-body">
<!-- <h6>April 25, 2022</h6> -->
<h5 class="card-title"><?php the_title(); ?></h5>
<p class="card-text"><?php the_excerpt()?></p>
Read the article
</div>
</div>
</div>
<?php
endwhile;
echo paginate_links(array(
'total' => $loop->max_num_pages,
'prev_text' => __('Previous'),
'next_text' => __('Next')
)) . "</div>";
wp_reset_postdata();
die();
}
/*
* Creating a function to create our CPT
*/
function fisher_custom_post_type_advisor() {
// Set UI labels for Custom Post Type
$labels = array(
'name' => _x( 'Advisor\'s', 'Post Type General Name', 'twentytwentyone' ),
'singular_name' => _x( 'advisor', 'Post Type Singular Name', 'twentytwentyone' ),
'menu_name' => __( 'Advisor\'s', 'twentytwentyone' ),
'parent_item_colon' => __( 'advisor', 'twentytwentyone' ),
'all_items' => __( 'All Advisor\'s', 'twentytwentyone' ),
'view_item' => __( 'View Advisor', 'twentytwentyone' ),
'add_new_item' => __( 'Add New Advisor', 'twentytwentyone' ),
'add_new' => __( 'Add New', 'twentytwentyone' ),
'edit_item' => __( 'Edit Advisor', 'twentytwentyone' ),
'update_item' => __( 'Update Advisor', 'twentytwentyone' ),
'search_items' => __( 'Search Advisor', 'twentytwentyone' ),
'not_found' => __( 'Not Found', 'twentytwentyone' ),
'not_found_in_trash' => __( 'Not found in Trash', 'twentytwentyone' ),
);
// Set other options for Custom Post Type
$args = array(
'label' => __( 'Advisor\'s', 'twentytwentyone' ),
'description' => __( 'Advisor\' news and reviews', 'twentytwentyone' ),
'labels' => $labels,
// Features this CPT supports in Post Editor
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions' ),
// You can associate this CPT with a taxonomy or custom taxonomy.
// 'taxonomies' => array( 'genres' ),
/* A hierarchical CPT is like Pages and can have
* Parent and child items. A non-hierarchical CPT
* is like Posts.
*/
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'advisors' ),
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'show_in_rest' => false,
);
// Registering your Custom Post Type
register_post_type( 'all-advisors', $args );
}
/* Hook into the 'init' action so that the function
* Containing our post type registration is not
* unnecessarily executed.
*/
add_action( 'init', 'fisher_custom_post_type_advisor', 0 );
function global_notice_meta_box() {
add_meta_box(
'advisor-first-name',
__( 'Advisor Detail', 'sitepoint' ),
'global_notice_meta_box_callback',
'all-advisors'
);
}
add_action( 'add_meta_boxes', 'global_notice_meta_box' );
function global_notice_meta_box_callback( $post ) {
// Add a nonce field so we can check for it later.
wp_nonce_field( 'fisher_advisor', 'fisher_advisor' );
global $fields;
$fields = [
array (
'key' => 'first_name',
'label'=> __( 'Full Name'),
'type' => 'text'
),
array (
'key' => 'role',
'label'=> __( 'Title'),
'type' => 'text'
),
array (
'key' => 'professional_certificate_short_form',
'label'=> __( 'Professional Certifications (Short)'),
'type' => 'text'
),
array (
'key' => 'professional_certificate',
'label'=> __( 'Professional Certifications'),
'type' => 'text'
),
array (
'key' => 'adress',
'label'=> __( 'Full Address'),
'type' => 'text'
),
array (
'key' => 'city',
'label' => __( 'Location'),
'type' => 'text'
),
array (
'key' => 'phone',
'label' => __( 'Phone' ),
'type' => 'tel'
),
array (
'key' => 'email',
'label' => __( 'Email' ),
'type' => 'email'
)
];
foreach ( $fields as $field ) {
$value = get_post_meta( $post->ID, '_advisor_'. $field['key'], true );
if ( $field['key'] == 'city' ) {
$args = [ 'post_type' => 'all-locations', 'posts_per_page' => -1 ];
$locations = new WP_Query($args);
if ( $locations->have_posts() ) {
echo '<label><span>' . $field['label'] .'</span>';
echo '<select name="advisor_' . $field['key'] . '">';
while ( $locations->have_posts() ) {
$locations->the_post();
echo '<option value="' . get_the_title() . '">' . get_the_title() . '</option>';
}
echo '</select></label>';
}
} else {
$value = get_post_meta( $post->ID, '_advisor_'. $field['key'], true );
echo '<label><span>' . $field['label'] .'</span> <input type="'. $field['type'] .'" name="advisor_' . $field['key'] . '" value="' . esc_attr( $value ) . '" /></label>';
echo '<br>';
}
}
}
function save_global_notice_meta_box_data( $post_id ) {
// Check if our nonce is set.
if ( ! isset( $_POST['fisher_advisor'] ) ) {
return;
}
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $_POST['fisher_advisor'], 'fisher_advisor' ) ) {
return;
}
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Check the user's permissions.
if ( isset( $_POST['post_type'] ) && 'all-advisors' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
}
else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
/* OK, it's safe for us to save the data now. */
// Make sure that it is set.
$fields = [
array (
'key' => 'first_name',
'label'=> __( 'Full Name'),
'type' => 'text'
),
array (
'key' => 'role',
'label'=> __( 'Title'),
'type' => 'text'
),
array (
'key' => 'professional_certificate_short_form',
'label'=> __( 'Professional Certifications (Short)'),
'type' => 'text'
),
array (
'key' => 'professional_certificate',
'label'=> __( 'Professional Certifications'),
'type' => 'text'
),
array (
'key' => 'adress',
'label'=> __( 'Full Address'),
'type' => 'text'
),
array (
'key' => 'city',
'label' => __( 'Location'),
'type' => 'text'
),
array (
'key' => 'phone',
'label' => __( 'Phone' ),
'type' => 'tel'
),
array (
'key' => 'email',
'label' => __( 'Email' ),
'type' => 'email'
)
];
foreach ( $fields as $field ) {
if ( ! isset( $_POST['advisor_' . $field['key']] ) ) return;
$sav_field = sanitize_text_field( $_POST['advisor_' . $field['key']] );
update_post_meta( $post_id, '_advisor_' . $field['key'], $sav_field );
}
}
add_action( 'save_post', 'save_global_notice_meta_box_data' );
/*****cpt for location ***/
/*
* Creating a function to create our CPT
*/
function fisher_custom_post_type_location() {
// Set UI labels for Custom Post Type
$labels = array(
'name' => _x( 'Location\'s', 'Post Type General Name', 'twentytwentyone' ),
'singular_name' => _x( 'Location', 'Post Type Singular Name', 'twentytwentyone' ),
'menu_name' => __( 'Location\'s', 'twentytwentyone' ),
'parent_item_colon' => __( 'Location', 'twentytwentyone' ),
'all_items' => __( 'All Location\'s', 'twentytwentyone' ),
'view_item' => __( 'View Location', 'twentytwentyone' ),
'add_new_item' => __( 'Add New Location', 'twentytwentyone' ),
'add_new' => __( 'Add New', 'twentytwentyone' ),
'edit_item' => __( 'Edit Location', 'twentytwentyone' ),
'update_item' => __( 'Update Location', 'twentytwentyone' ),
'search_items' => __( 'Search Location', 'twentytwentyone' ),
'not_found' => __( 'Not Found', 'twentytwentyone' ),
'not_found_in_trash' => __( 'Not found in Trash', 'twentytwentyone' ),
);
// Set other options for Custom Post Type
$args = array(
'label' => __( 'Location\'s', 'twentytwentyone' ),
'description' => __( 'Location\' news and reviews', 'twentytwentyone' ),
'labels' => $labels,
// Features this CPT supports in Post Editor
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions' ),
// You can associate this CPT with a taxonomy or custom taxonomy.
// 'taxonomies' => array( 'genres' ),
/* A hierarchical CPT is like Pages and can have
* Parent and child items. A non-hierarchical CPT
* is like Posts.
*/
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'locations' ),
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'show_in_rest' => false,
);
// Registering your Custom Post Type
register_post_type( 'all-locations', $args );
}
/* Hook into the 'init' action so that the function
* Containing our post type registration is not
* unnecessarily executed.
*/
add_action( 'init', 'fisher_custom_post_type_location', 0 );
/****locatin-meta-box**** */
function global_notice_meta_box_location() {
add_meta_box(
'advisor-first-name',
__( 'Location Detail', 'sitepoint' ),
'global_notice_meta_box_location_callback',
'all-locations'
);
}
add_action( 'add_meta_boxes', 'global_notice_meta_box_location' );
function global_notice_meta_box_location_callback( $post ) {
// Add a nonce field so we can check for it later.
wp_nonce_field( 'fisher_location', 'fisher_location' );
global $fields;
$fields = [
array (
'key' => 'city',
'label'=> __( 'city'),
'type' => 'text'
),
array (
'key' => 'adress',
'label'=> __( 'adress'),
'type' => 'text'
),
array (
'key' => 'phone',
'label' => __( 'Phone' ),
'type' => 'tel'
),
array (
'key' => 'lati',
'label' => __( 'latitutde' ),
'type' => 'text'
),
array (
'key' => 'langi',
'label' => __( 'langitude' ),
'type' => 'text'
),
];
foreach ( $fields as $field ) {
$value = get_post_meta( $post->ID, '_location_'. $field['key'], true );
echo '<label><span>' . $field['label'] .'</span> <input type="'. $field['type'] .'" name="location_' . $field['key'] . '" value="' . esc_attr( $value ) . '" /></label>';
echo '<br>';
}
}
function save_global_notice_meta_box_location_data( $post_id ) {
// Check if our nonce is set.
if ( ! isset( $_POST['fisher_location'] ) ) {
return;
}
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $_POST['fisher_location'], 'fisher_location' ) ) {
return;
}
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Check the user's permissions.
if ( isset( $_POST['post_type'] ) && 'all-locations' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
}
else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
/* OK, it's safe for us to save the data now. */
// Make sure that it is set.
$fields = [
array (
'key' => 'city',
'label'=> __( 'city'),
'type' => 'text'
),
array (
'key' => 'adress',
'label'=> __( 'adress'),
'type' => 'text'
),
array (
'key' => 'phone',
'label' => __( 'Phone' ),
'type' => 'tel'
),
array (
'key' => 'lati',
'label' => __( 'latitutde' ),
'type' => 'text'
),
array (
'key' => 'langi',
'label' => __( 'langitude' ),
'type' => 'text'
),
];
foreach ( $fields as $field ) {
if ( ! isset( $_POST['location_' . $field['key']] ) ) return;
$sav_field = sanitize_text_field( $_POST['location_' . $field['key']] );
update_post_meta( $post_id, '_location_' . $field['key'], $sav_field );
}
}
When the below was added, I started getting a blank screen for wordpress when I go to /wp-admin
add_action( 'save_post', 'save_global_notice_meta_box_location_data' );
?>
<?php
//SETTING UP THE PAGE
function set_page() {
add_menu_page('Social Media Links', 'Social Media Links', 'manage_options', 'theme_settings', 'the_page', 'dashicons-share', 40);
}
//CALLING THE FUNCTION
add_action('admin_menu', 'set_page');?>
<?php //THE PAGE
function the_page() {?>
<link rel="stylesheet" href="<?php echo get_template_directory_uri()?>/css/bootstrap.min.css">
<legend style="background: #2271b1;color: #fff;padding: 15px 30px;margin-bottom: 60px;margin-top: 10px;padding-right: 85px;max-width: 99%;">Social media linked accounts</legend>
<div class="container"><div class="row"><div class="col-md-12">
<form method="post" action="options.php">
<?php settings_fields('theme_settings'); ?>
<?php $options = get_option('theme_settings'); ?>
<?php if ($_REQUEST['settings-updated']) : ?>
<div class="updated">
<p><strong class="alret">
<?php _e('Options saved'); ?>
</strong></p>
</div>
<?php endif; ?>
<div class="the-container">
<div id="social" class="container tab-pane fade active show"><br>
<fieldset>
<?php $social_arr = ['facebook','twitter','linkedin','youtube'];
foreach($social_arr as $social){?>
<div class="form-group form_builder_row facebook_container row">
<div class="col-md-2 form_builder_col">
<label class="control-label <?php echo $social;?>" for="<?php echo $social;?>">
<?php echo ucfirst($social);?>:</label>
</div>
<div class="col-md-6 form_builder_col">
<input type="text" class=" form_builder_field form-control input-text field_<?php echo $social;?>" id="<?php echo $social;?>" name="theme_settings[<?php echo $social;?>]" value="<?php echo $options[$social];?>" placeholder="<?php echo ucfirst($social);?>">
</div></div>
<?php }?>
</fieldset>
</div>
</div>
<p class="mt-4">
<input name="theme_settings[submit]" id="submit" value="Save Changes" type="submit" class="button button-primary btn-md ml-3">
</p>
</form>
</div></div></div>
<?php } ?>
<?php
//REGISTERING SETTINGS AND FIELDS
function register_settings_and_fields() {
register_setting('theme_settings','theme_settings');
}
add_action('admin_init', 'register_settings_and_fields');
?>
Have you opened wp-config.php? and set WP_DEBUG to true; this can show some errors more intuitively
Don't use function names like this the_page set_page use a prefix before function name e.g.: lefty_wp_set_page , lefty_wp_the_page or give a function a meaningful name, don't just copy paste things from internet, do some modifications in it to avoid conflicts.
I have a nested element called Hero Slider. Hero slider is the container and it can only contain a Slider item.
However, my shortcode is being shown in the WPBakery backend maybe suggesting a syntax error, but I cannot see anything that is causing it to appear this way:
The block doesn't even appear when adding a new element.
Here's my custom element: (init.php)
<?php
if (!defined('ABSPATH')) die('-1');
class vcHeroSlider extends WPBakeryShortCode {
// 1. Define constants at compile time (used in mapping)
const slug = 'tp_hero_slider';
const base = 'tp_hero_slider';
// 2. Integrate with hooks
function __construct() {
// For the parent wrapper
add_action( 'vc_before_init', array( $this, 'tp_heroSlider_mapping' ) );
add_shortcode( 'tp_hero_slider', array( $this, 'tp_heroSlider_html' ));
// For child / nested
add_action( 'vc_before_init', array( $this, 'tp_heroSlider_content_mapping' ) );
add_shortcode( 'tp_hero_slider_content', array( $this, 'tp_heroSlider_content_html' ));
}
// 3. Map for parent element
public function tp_heroSlider_mapping() {
vc_map(
array(
'icon' => get_template_directory_uri().'/assets/src/images/html.svg',
'name' => __( 'Hero Slider' , "text-domain" ),
'base' => 'tp_hero_slider',
'description' => __( 'Add slick slider to your page.', "text-domain" ),
'as_parent' => array('only' => 'tp_hero_slider_content'), // set as parent of the content map/html
'content_element' => true,
'show_settings_on_create' => false,
"js_view" => 'VcColumnView',
"category" => __('Hero', "text-domain" ),
'params' => array(
array(
"type" => "textfield",
"heading" => __( "Extra Class Name", "text-domain" ),
"param_name" => "el_class",
"description" => __( "Extra class to be customized via CSS", "text-domain" )
),
array(
'type' => 'css_editor',
'heading' => __( 'Custom Design Options', "text-domain" ),
'param_name' => 'css',
'group' => __( 'Design options', "text-domain" ),
),
),
)
);
}
// 4. Map for child element
public function tp_heroSlider_content_mapping() {
vc_map(
array(
'icon' => get_template_directory_uri().'/assets/src/images/html.svg',
'name' => __('Slider Item', "text-domain" ),
'base' => 'tp_hero_slider_content',
'description' => __( 'Add slide to hero.', "text-domain" ),
"category" => __('Content', 'text-domain'),
'content_element' => true,
'as_child' => array('only' => 'tp_hero_slider'),
'params' => array(
array(
'type' => 'textfield',
'heading' => __( 'Title', 'text-domain'),
'param_name' => 'title',
'value' => esc_html__( '', 'text-domain'),
'admin_label' => true,
'weight' => 0,
'group' => __( 'Content', 'my-text-domain' ),
),
array(
'type' => 'textarea',
'class' => '',
'heading' => __( 'Standfirst', 'text-domain'),
'param_name' => 'standfirst',
'value' => esc_html__( '', 'text-domain'),
'admin_label' => false,
'weight' => 0,
'group' => __( 'Content', 'my-text-domain' ),
)
),
)
);
}
// 5. Mapping markup of parent
public function tp_heroSlider_html( $atts, $content = null) {
$output = '';
$el_class = '';
extract(
shortcode_atts(
array(
'el_class' => '',
), $atts
)
);
static $i = 0;
$output = '<div id="slickslider-'.$i++.'" class="Slick-Slider heroSlider">'. do_shortcode($content) .'</div>';
return $output;
}
// 6. Mapping markup of child
public function tp_heroSlider_content_html( $atts, $content = null ) {
$output = '';
extract(
shortcode_atts(
array(
'title' => '',
'standfirst' => '',
), $atts
)
);
$background_img = wp_get_attachment_image_src(intval($background_img), 'full');
$background_img = $background_img[0];
$output .= '
<!-- Slide -->
<div class="heroSlider__slide">
<div class="overlay"></div>
';
$output .= '
<div class="container">
<div class="row justify-content-center justify-content-lg-start">
<div class="col-10 col-md-6 d-flex flex-column text-center text-lg-left content">';
if (!empty($title)) {
$output .= '<h1>' . $title . '</h1>';
}
if (!empty($standfirst)) {
$output .= '<p class="standfist">' . $standfirst . '</p>';
}
$output .= '
</div>
</div>
</div>
</div>
<!-- Slide -->
';
return $output;
}
}
// 7. Add the container functionality (so you can choose a slider element within the hero_slider element
if(class_exists('WPBakeryShortCodesContainer')){
class WPBakeryShortCode_tp_hero_slider extends WPBakeryShortCodesContainer {}
}
if(class_exists('WPBakeryShortCode')){
class WPBakeryShortCode_tp_hero_slider_content extends WPBakeryShortCode {}
}
new vcHeroSlider(); ?>
How I've added new element:
add_action( 'vc_before_init', 'vc_before_init_actions' );
function vc_before_init_actions() {
$theme = get_template_directory();
require_once( $theme.'/vc_elements/hero-slider/init.php');]
}
Although I don't believe the above is the issue, because I have several other elements defined like that and they all work.
I am modifying a wordpress theme 'jobify' . In their demo they have a 'search hero' widget with a button which takes you to a jobs listings page. Inspecting in chrome:
<form class="job_search_form job_search_form--flat"
action="https://jobify-demos.astoundify.com/classic/find-a-job/"
method="GET">
Their 'find-a-job' page which you get taken to with the button has google maps which I don't want. So I have created a new [jobs] page I named 'job-search' without the map. If I edit the above url to that in chrome inspector then the button outputs the search results correctly on my new page. following this
I have now spent 2 days going through all the widget php code trying to find where I change that GET command url on this widget button from 'find-a-job' to 'job-search'. Adjusting this on a newly made search page seems straightforward as seen on this SO question
I have read about customising their widgets here and thought it would be in the class-widget-search-hero.php file (below). I have also checked its scss file but don't see anything there. So many hours looking, is it something as simple as deleting one of the two [jobs] pages? Thank you.
<?php
/**
* Home: Search Hero
*
* #package Jobify
* #category Widget
* #since 3.0.0
*/
class Jobify_Widget_Search_Hero extends Jobify_Widget {
public function __construct() {
$this->widget_description = __( 'Display a "hero" search area.', 'jobify' );
$this->widget_id = 'jobify_widget_search_hero';
$this->widget_cssclass = 'widget--home-hero-search';
$this->widget_name = __( 'Jobify - Page: Search Hero', 'jobify' );
$this->control_ops = array(
'width' => 400,
);
$this->settings = array(
'home widgetized' => array(
'std' => __( 'Homepage/Widgetized', 'jobify' ),
'type' => 'widget-area',
),
'height' => array(
'type' => 'select',
'std' => 'medium',
'label' => __( 'Hero Height', 'jobify' ),
'options' => array(
'small' => __( 'Small', 'jobify' ),
'medium' => __( 'Medium', 'jobify' ),
'large' => __( 'Large', 'jobify' ),
),
),
'margin' => array(
'type' => 'checkbox',
'std' => 1,
'label' => __( 'Add standard spacing above/below widget', 'jobify' ),
),
'text_color' => array(
'type' => 'colorpicker',
'std' => '#ffffff',
'label' => __( 'Text Color:', 'jobify' ),
),
'title' => array(
'type' => 'text',
'std' => '',
'label' => __( 'Title:', 'jobify' ),
),
'description' => array(
'type' => 'text',
'std' => '',
'label' => __( 'Description:', 'jobify' ),
'rows' => 5,
),
'image' => array(
'type' => 'image',
'std' => '',
'label' => __( 'Background Image:', 'jobify' ),
),
'background_position' => array(
'type' => 'select',
'std' => 'center center',
'label' => __( 'Image Position:', 'jobify' ),
'options' => array(
'left top' => __( 'Left Top', 'jobify' ),
'left center' => __( 'Left Center', 'jobify' ),
'left bottom' => __( 'Left Bottom', 'jobify' ),
'right top' => __( 'Right Top', 'jobify' ),
'right center' => __( 'Right Center', 'jobify' ),
'right bottom' => __( 'Right Bottom', 'jobify' ),
'center top' => __( 'Center Top', 'jobify' ),
'center center' => __( 'Center Center', 'jobify' ),
'center bottom' => __( 'Center Bottom', 'jobify' ),
'center top' => __( 'Center Top', 'jobify' ),
),
),
'cover_overlay' => array(
'type' => 'checkbox',
'std' => 1,
'label' => __( 'Use transparent overlay', 'jobify' ),
),
);
if ( jobify()->get( 'wp-job-manager-resumes' ) ) {
$what = array(
'what' => array(
'type' => 'select',
'std' => 'job',
'label' => __( 'Search:', 'jobify' ),
'options' => array(
'job' => __( 'Jobs', 'jobify' ),
'resume' => __( 'Resumes', 'jobify' ),
),
),
);
$this->settings = $what + $this->settings;
}
parent::__construct();
}
function widget( $args, $instance ) {
extract( $args );
$text_align = isset( $instance['text_align'] ) ? esc_attr( $instance['text_align'] ) : 'left';
$background_position = isset( $instance['background_position'] ) ? esc_attr( $instance['background_position'] ) : 'center center';
$overlay = isset( $instance['cover_overlay'] ) && 1 == $instance['cover_overlay'] ? 'has-overlay' : 'no-overlay';
$margin = isset( $instance['margin'] ) && 1 == $instance['margin'] ? true : false;
$height = isset( $instance['height'] ) ? esc_attr( $instance['height'] ) : 'medium';
if ( ! $margin ) {
$before_widget = str_replace( 'widget--home ', 'widget--home widget--home--no-margin ', $before_widget );
}
$image = isset( $instance['image'] ) ? esc_url( $instance['image'] ) : null;
$content = $this->assemble_content( $instance );
$what = isset( $instance['what'] ) ? esc_attr( $instance['what'] ) : 'job';
global $is_flat;
$is_flat = true;
ob_start();
?>
<?php echo $before_widget; ?>
<div class="hero-search hero-search--<?php echo esc_attr( $overlay ); ?> hero-search--height-<?php echo esc_attr( $height ); ?>" style="background-image:url(<?php echo $image; ?>); ?>; background-position: <?php echo $background_position; ?>">
<div class="container">
<?php echo $content; ?>
<?php locate_template( array( $what . '-filters-flat.php' ), true, false ); ?>
</div>
</div>
<?php echo $after_widget; ?>
<?php
$content = ob_get_clean();
echo apply_filters( $this->widget_id, $content );
}
private function assemble_content( $instance ) {
$text_color = isset( $instance['text_color'] ) ? esc_attr( $instance['text_color'] ) : '#fff';
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
$content = isset( $instance['description'] ) ? $instance['description'] : '';
$output = '<div class="hero-search__content" style="color:' . $text_color . '">';
$output .= '<h2 class="hero-search__title" style="color:' . $text_color . '">' . $title . '</h2>';
$output .= wpautop( $content );
$output .= '</div>';
return $output;
}
}
The solution (if not technical answer) was actually very easy once found.
After reading this tutorial and seeing the line:
$action_page_id = get_option('job_manager_jobs_page_id');
Then searching "job_manager_jobs_page_id" and finding this on github I discovered it exists under the job manager settings /wp-admin/edit.php?post_type=job_listing&page=job-manager-settings#settings-job_pages where you just change the 'Job Listings' page in the drop down from 'find a job' to my new 'job search' page. All working.
i use option tree list item for getting social icon & links.but i cannot get data from backend.
array(
'id' => 'social_icon',
'label' => __( 'Footer Social Icons & links', 'theme-text-domain' ),
'desc' => __( '', 'theme-text-domain' ),
'std' => '',
'type' => 'list-item',
'section' => 'header_footer',
'rows' => '',
'post_type' => '',
'taxonomy' => '',
'min_max_step'=> '',
'class' => '',
'condition' => '',
'operator' => 'and',
'settings' => array(
array(
'id' => 'social_icon_fb',
'label' => __( 'link', 'theme-text-domain' ),
'desc' => '',
'std' => '',
'type' => 'text',
'rows' => '10',
'post_type' => '',
'taxonomy' => '',
'min_max_step'=> '',
'class' => '',
'condition' => '',
'operator' => 'and'
),
array(
'id' => 'social_icon_upl',
'label' => __( 'icon', 'theme-text-domain' ),
'desc' => 'the best sixe for icon is 31x31.',
'std' => '',
'type' => 'upload',
'rows' => '10',
'post_type' => '',
'taxonomy' => '',
'min_max_step'=> '',
'class' => '',
'condition' => '',
'operator' => 'and'
),
)
)
and i want to use this in
<ul id="icons">
<li>
<img src="<?php get_option_tree( 'social_icon_upl', '', 'true' ); ?>" alt="">
</li>
</ul>
i use this to get data from backend.is this correct?? if no so what should be the code to get data.
Try this code
<?php
if ( function_exists( 'ot_get_option' ) ) {
/* get the slider array */
$slides = ot_get_option( 'social_icon', array() );
if ( ! empty( $slides ) ) {
foreach( $slides as $slide ) {
echo '
<li>
<img src="'.$slide['social_icon_upl'].'" alt="">
</li>
';
}
}
}
?>
list item always return array. you have to use foreach loop for getting every row of array. code is describe bellow.
*<?php
if ( function_exists( 'ot_get_option' ) ) {
$your_listitems_array = ot_get_option( 'your_listitems_slug', array() );
if ( ! empty( $your_listitems_array ) ) {
foreach( $your_listitems_array as $your_listitem) {
echo $your_listitem['your_listitem_option_slug'];
}
}
}
?>*