I have implemented LIKE and UNLIKE buttons on a post page, where the LIKE button submits a form to create a CPT using a page reload, and the UNLIKE button deletes the CPT without a page scroll due to AJAX. I want to improve the UX by using JavaScript for a page refresh upon successful form submission.
Solution:
To reload the page after a successful form submission without a clunky scroll, use jQuery’s ajaxComplete event to trigger a JavaScript reload. This will refresh the page only after the AJAX request completes.
This approach triggers a refresh right after the AJAX completion, maintaining the user's scroll position.
I want to remove the author name, date, and post navigation (previous/next post) from my content template on specific posts.
Solution:
For Navigation (Previous/Next Post): In your content template, search for the code responsible for post navigation, usually found near . Remove or comment out this section to disable the navigation links.
For Author Name and Date: These elements are likely generated by the Astra theme. Check the Astra theme options in the WordPress Customizer (Appearance > Customize) for settings to hide the author and date. If no option exists, contact Astra support for further assistance.
I'm encountering a PHP notice: "Only variables should be passed by reference" due to code in my check_filetype.php file. The code, created years ago, is producing this warning in the logs.
Solution:
This warning occurs because PHP prefers variables over direct function calls in end() statements. To resolve this, assign the results of explode() functions to variables before using end(). Here’s an updated version of your code:
<?php
/**
* Check if the user uploaded job CPT file is a pdf.
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
add_shortcode( 'check_filetype', 'func_check_file_type' );
function func_check_file_type( $atts ) {
$atts = shortcode_atts( array(
'url' => '',
), $atts );
$url_parts = explode( '/', $atts['url'] );
$file_name = end( $url_parts );
$file_extension = explode( '.', $file_name );
return end( $file_extension );
}
Explanation of Changes:
- Saved the results of explode() into $url_parts and $file_extension.
- Applied end() on these variables rather than directly on the function calls.
I am trying to use Toolset custom templates for my custom posts, but WordPress defaults to my theme's templates (Twenty Twenty-Four). I've created a Toolset content template, but it doesn’t apply automatically.
Solution:
Toolset custom templates don’t work with block-based themes like Twenty Twenty-Four, as these themes don’t use PHP-based templates. Alternatively, consider using a PHP-based theme, which supports Toolset custom templates directly.