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.
The customer wanted to filter a view on their website so that only specific URL parameters, such as "category=blog," remain visible in the URL after filtering. By default, all parameters were displayed, which cluttered the URL with unnecessary information.
Solution:
A combination of PHP and JavaScript was used to selectively retain only the category parameter in the URL after filtering. Here’s the implemented approach:
1- A hidden field was added to capture and maintain the category parameter, using a custom function in the theme’s functions.php file:
add_filter('wpv_filter_end_filter_form', 'add_hidden_category_param', 99, 4);
function add_hidden_category_param($out, $view_settings, $view_id, $is_required) {
$views = array(12345); // Replace with the View ID
if (in_array($view_id, $views) && $is_required) {
$category = isset($_GET['category']) ? $_GET['category'] : '';
$out = '<input type="hidden" id="category" name="category" value="' . esc_attr($category) . '" />' . $out;
}
return $out;
}
This function captures the category parameter and stores it in a hidden input field to ensure it persists through the filter updates.
2- In the View's Custom JavaScript section, this code was added to ensure only the category parameter remains visible in the URL
jQuery(document).ready(function($) {
$(document).on('js_event_wpv_parametric_search_form_updated', function(event, data) {
var url = new URL(window.location);
var category = url.searchParams.get("category");
jQuery('#category').val(category); // Update hidden input field with the category parameter
// Update the URL to show only the category parameter
let params = new URLSearchParams({ category: category });
window.history.replaceState({}, '', `${url.pathname}?${params.toString()}`);
});
});
This JavaScript ensures the URL updates to include only the category parameter after filtering, creating a cleaner URL.