Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Hook add_action into specific div

$
0
0

Replies: 0

Hi, I’m new to php and having trouble displaying a certain hook into a specific existing div within a post template.

CONTEXT: I used the following tutorial to add a custom field and display it onto a page using my child theme functions.php – it worked perfectly!

TUTORIAL: https://wpjobmanager.com/document/tutorial-adding-a-salary-field-for-jobs

MY ISSUE: Using the same tutorial as a guide, I’m also trying to display a LinkedIn link on a different part of the post, BUT I can’t seem to position it INSIDE an EXISTING Div on the post template, i.e. <div class=”company”>MY LINKEDIN LINK HOOKED HERE</div>. I can only seem to position it OUTSIDE this div or in a newly created Div.

I want to stick with the functions.php method rather than editing the template file directly.

Can anyone help/advise? – Thanks in advance!

CODE: I’ve included the full code for context but the issue (I’m fairly certain) is in the (3) snippet below.

ASK: How to display a custom add_action hook – $company_linkedin – INSIDE a specific div on an existing post template using the functions.php method?

I’ve included a link to the post. You can see the word ‘hirewave’ floating above the light blue div, rather than inside it, as I would like.

// (1) Add the field to the frontend

add_filter( ‘submit_job_form_fields’, ‘frontend_add_company_field’ );

function frontend_add_company_field( $fields ) {
$fields[‘company’][‘company_linkedin’] = array(
‘label’ => __( ‘LinkedIn’, ‘wp-job-manager’ ),
‘type’ => ‘text’,
‘required’ => false,
‘placeholder’ => __( ‘LinkedIn URL’, ‘wp-job-manager’ ),
‘priority’ => 9
);
return $fields;
}

// (2) Add the field to admin

add_filter( ‘job_manager_job_listing_data_fields’, ‘admin_add_company_field’ );

function admin_add_company_field( $fields ) {
$fields[‘_company_linkedin’] = array(
‘label’ => __( ‘LinkedIn’, ‘wp-job-manager’ ),
‘type’ => ‘text’,
‘placeholder’ => __( ‘LinkedIn URL’, ‘wp-job-manager’ ),
‘description’ => ”
);
return $fields;
}

// (3) Display “LinkedIn” on the single job page

add_action( ‘single_job_listing_start’, ‘the_company_linkedin’, 30 );

function the_company_linkedin( $before = ”, $after = ”, $echo = true, $post = null ) {
$company_linkedin = get_the_company_linkedin( $post );

if ( strlen( $company_linkedin ) == 0 )
return;

$company_linkedin = esc_attr( strip_tags( $company_linkedin ) );
$company_linkedin = $before . ‘‘ . $company_linkedin . ‘‘ . $after;

if ( $echo )
echo $company_linkedin;
else
return $company_linkedin;
}

function get_the_company_linkedin( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== ‘job_listing’ )
return;

$company_linkedin = $post->_company_linkedin;

if ( strlen( $company_linkedin ) == 0 )
return;

if ( strpos( $company_linkedin, ‘@’ ) === 0 )
$company_linkedin = substr( $company_linkedin, 1 );

return apply_filters( ‘the_company_linkedin’, $company_linkedin, $post );
}


Viewing all articles
Browse latest Browse all 59525

Trending Articles