What sort of code are you using? It’s possible that some snippets require a little bit of modification when transferring them from functions.php to code snippets, as code snippets run slightly earlier in the WordPress load order to allow for greater customisation.
So this is what I have so far:
DISPLAY LAST UPDATE STAMP
add_filter( 'genesis_post_info', 'sp_post_info_filter' );
function sp_post_info_filter($post_info) {
if ( !is_page() ) {
$post_info = 'Last Updated on [post_modified_date] by [post_author_posts_link] [post_edit]
<br />[disclosure]';
return $post_info;
}}
DISCLOSURE LINK IN TITLE AREA
add_shortcode( 'disclosure', 'genesis_disclosure_link_shortcode' );
function genesis_disclosure_link_shortcode( $atts ) {
$link = sprintf( '<a href="%s">%s</a>', esc_url( 'https://www.understandfinances.com/disclosure' ), 'Disclosure Policy' );
$defaults = array(
'after' => '',
'before' => __( 'This post may contain affiliate links. Please read the ', 'genesis' ),
'link' => $link,
);
$atts = shortcode_atts( $defaults, $atts, 'disclosure' );
$output = sprintf( '<span %s>', genesis_attr( 'disclosure-policy' ) ) . $atts['before'] . $atts['link'] . $atts['after'] . '</span>';
return $output;
}
CUSTOMIZE FOOTER
remove_action( 'genesis_footer', 'genesis_do_footer' );
add_action( 'genesis_footer', 'sp_custom_footer' );
function sp_custom_footer() {
?>
<span class="nav-footer" style="font-size: 13px" align="center">Copyright © 2018 – <?php echo date(Y); ?> EJNterprises, Inc. <a href="https://understandfinances.com/disclosure">Disclosure Policy</a> · <a href="https://understandfinances.com/privacy-policy">Privacy Policy</a></span>
<?php
}
-
This reply was modified 4 years, 11 months ago by Jan Dembowski.
-
This reply was modified 4 years, 11 months ago by Jan Dembowski. Reason: Formatting
Hi, i have the same problem with the code to add new fields in wp-job-manager job form. It should be very simplex. It works if used in function.php, but doesn’t work using code snippets. below code:
`add_filter( ‘submit_job_form_fields’, ‘frontend_add_salary_field’ );
function frontend_add_salary_field( $fields ) {
$fields[‘job’][‘job_salary’] = array(
‘label’ => __( ‘Salary ($)’, ‘job_manager’ ),
‘type’ => ‘text’,
‘required’ => true,
‘placeholder’ => ‘e.g. 20000’,
‘priority’ => 7
);
return $fields;
}
Can you help me to understand what’s the matter? Thanks
If this happens, that relates with the order, how code executed.
The situation might be different if you add something to functions.php or using Code Snippet.
Also the priority setting of each Code Snippet is relevant. If you ever refer to some function, which you have been defined in another Code Snippet, do these:
- Set bigger pririty value for the snippet, which calls the function.
- Use if(functions_exists(yourFunctionName){ // do something using yourFunctionName()}
The latter is needed, because Code Snippet can’t reliable check, if your own function exists or not.
I tried your tip, but It still doesn’t work! Any other suggestions?
Below the code:
add_filter( ‘submit_job_form_fields’, ‘frontend_add_salary_field’ );
if(function_exists(‘frontend_add_salary_field’)){
function frontend_add_salary_field( $fields ) {
$fields[‘job’][‘job_salary’] = array(
‘label’ => __( ‘Salary ($)’, ‘job_manager’ ),
‘type’ => ‘text’,
‘required’ => true,
‘placeholder’ => ‘e.g. 20000’,
‘priority’ => 7
);
return $fields;
};
}
@danielerocchi please create your own thread when asking for help instead of posting on an existing thread. It makes it easier if we can respond to one person at a time.
@ejnterprises the problem with your code is that remove_action()
is a little touchy – it will only work if called after the action has been added. This is fine for functions.php
as the child theme is included after the parent theme is finished, but code snippets run a little earlier in the loading process.
In this case, the fix is to only call remove_action()
after Genesis has been set up, like this:
add_action( 'after_setup_theme', function () {
remove_action( 'genesis_footer', 'genesis_do_footer' );
} );
i have the same problem, custom code works on child functions.php and not in code snippet:
This is the code (i need to filter get_the_data from layouts’ parant theme)
function xyz_filter_publish_dates( $the_date, $d, $post ) {
if ( class_exists('SitePress') && ICL_LANGUAGE_CODE == 'en') {
return date( 'd/m/Y', strtotime( $the_date ) );
} else {
return $the_date;
}
}
add_action( 'get_the_date', 'xyz_filter_publish_dates', 10, 3 );
i try to change priority both code and code snippet (from backend wp) but nothing.