I try to wrap the posts items with the "single_post_wrap" hook but it inserts pared <a> tag - wordpress

I am newbie to coding and I have an issue with Post Widget, I am trying to wrap the posts items with individual URL of Post in Advanced Post widget of PowerPack elements addon in grid layout through hook but it inserts pared tag "". Are there any solutions?
function single_post_after( $post_id, $settings ) {
echo '<a href="#">';
}
add_action( 'ppe_after_single_post', 'single_post_after', 10, 2 );
function pp_post_content_before( $post_id, $settings ) {
echo '</a>';
}
add_action( 'ppe_before_single_post_content', 'pp_post_content_before', 10, 2 );
(https://i.stack.imgur.com/wuT9Q.jpg)(https://i.stack.imgur.com/CTf0s.jpg)

Related

WordPress apply_filters( 'the_content', 'func_name' ) not working inside another hook

I am trying to display PAGE Content inside Product Single Page based on some conditions met.
I am showing this Page Content at a particular action hook place of Product Single Page
as shown in below code :
add_filter( 'wp', array( $this, 'txb_add_page_check_single' ) );
public function txb_add_page_check_single() {
if ( is_single() ) {
if ( some_condition_met ) {
add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'txb_display_page_content_single' ) );
}
}
}
public function txb_display_page_content_single() {
$txb_all_data_array = get_post( $some_page_id );
//echo apply_filters( 'the_content', get_post_field( 'post_content', $txb_all_data_array->ID ) ); // CASE 1 : NOT WORKING
$get_content_data = $txb_all_data_array->post_content;
echo $get_content_data; //CASE 2 : Working
}
Here // CASE 1 is not working.
// CASE 1 is returning a CURRENT SINGLE PRODUCT CONTENT, but I want PAGE CONTENT of $some_page_id.
I want to get it work with // CASE 1 , Because Content may have Shortcode or any other Gutenberg block.
PS : hook name woocommerce_after_add_to_cart_quantity will come dynamically , based on some conditions met.
Place this code in your active theme's functions.php file
OR Custom Plugin's main file
add_filter('se152488_the_content', 'wptexturize');
add_filter('se152488_the_content', 'convert_smilies');
add_filter('se152488_the_content', 'convert_chars');
add_filter('se152488_the_content', 'wpautop');
add_filter('se152488_the_content', 'shortcode_unautop');
add_filter('se152488_the_content', 'prepend_attachment');
then , call content like this :
echo apply_filters( 'se152488_the_content' , $txb_all_data_array->post_content );
Credit : https://wordpress.stackexchange.com/a/152493/110795
The variable $some_page_id needs to be set, its passing null and you're getting the CURRENT SINGLE PRODUCT CONTENT.

How create new custom fields for my Theme in Wordpress

I have created a super simple theme. What i want to have is the ability to define an array of 3 fields for each post and page.
For example having the fields: Name, Link and a Dropdown for Type
Additionally i want to add multiple items of these "field sets" per post/page. I couldn't find any documentation on this but always results in Google which led me to WP Plugins. In general this is ood, cause in this case this seems to be possible programmatically, but bad cause i couldn't find any kind of information on this.
Hopefully someone can help me.
You are looking for custom meta boxes, with the add_meta_box() function:
Adds a meta box to one or more screens.
Source # https://developer.wordpress.org/reference/functions/add_meta_box/
And the add_meta_boxes action hook.
Fires after all built-in meta boxes have been added:
Source # https://developer.wordpress.org/reference/hooks/add_meta_boxes/
A simple example would be if we wanted to add a "Listening to..." custom meta box, to share our mood while writing a post.
<?php
add_action( 'add_meta_boxes', 'add_meta_listening_to' );
function add_meta_listening_to() {
add_meta_box(
'meta_listening_to', //id
'Listening to ...', //title
'listeningto', //callback
'post', //screen &/or post type
'normal', //context
'high', //priority
null //callback_args
);
};
function listeningto( $post ) { //function handle same as callback
$ListeningToInput = get_post_meta( $post->ID, 'ListeningToInput', true );
echo '<input name="listening_to_input" type="text" placeholder="Listening to ..." value="'. $ListeningToInput .'" style="width:100%;">';
};
add_action( 'save_post', 'save_meta_listening_to' );
function save_meta_listening_to( $post_ID ) {
if ( isset( $_POST[ 'listening_to_input' ] ) ) {
update_post_meta( $post_ID, 'ListeningToInput', esc_html( $_POST[ 'listening_to_input' ] ) );
};
}; ?>
Then to display on the front end, we would use the following:
<?php echo get_post_meta( $post->ID, 'ListeningToInput', true ); ?>
Learn more
Learn more about the Custom Meta Boxes # https://developer.wordpress.org/plugins/metadata/custom-meta-boxes/

WooCommerce Shop page thumbnail wrap

I am looking at this: https://www.businessbloomer.com/woocommerce-visual-hook-guide-archiveshopcat-page/
I would like to wrap thumb in shop page into another div.
If I use following code I could achieve something, but the problem is many themes remove or dont use woocommerce_before_shop_loop_item_title and use some different code and I cannot effectively do my action.
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
add_action( 'woocommerce_before_shop_loop_item_title', 'my_woocommerce_before_shop_loop_item_title', 10 );
function my_woocommerce_before_shop_loop_item_title() {
global $product;
$post_id = $product->get_id();
$html = woocommerce_get_product_thumbnail('woocommerce_thumbnail');
echo '<div class="my">' . $html . '</div>';
}
Is there action or hook that processes product thumbnail to which I could do my own action? Regardless of what is happening before and after that?
Please try to implement in this way.
//replace the functionprefix with your functions prefix
function functionprefix_wrap_loop_product_image() {
if ( ! class_exists( 'WooCommerce' ) ) return; //* exit if WooCommerce not active
add_action( 'woocommerce_before_shop_loop_item_title' , 'functionprefix_product_loop_image_wrapper_open', 10 );
add_action( 'woocommerce_shop_loop_item_title' , 'functionprefix_product_loop_image_wrapper_close', 10 );
}
add_action( 'woocommerce_before_shop_loop' , 'functionprefix_wrap_loop_product_image', 3 );
//replace the functionprefix with your functions prefix
function functionprefix_product_loop_image_wrapper_open() {
echo '<div class="image-wraper">';
}
function functionprefix_product_loop_image_wrapper_close() {
echo '</div>';
}

WordPress How to Keep the_content filter for my cpt from affecting other posts on the same page

I am using a custom post type for the slide in my theme. I'm trying to remove wpautop from the cpt using the_content filter hook, and it works using the following code, but it also removes it wpautop from the other queries on the same page. Here is the code:
add_filter( 'the_content', 'remove_autop_for_post_type', 0 );
function remove_autop_for_post_type( $content )
{
if('par2_slide' === get_post_type(get_the_ID())){
remove_filter( 'the_content', 'wpautop' );
return $content;
};
return $content;
};
Adding a second condition to include "! is_main_query() like so:
if('par2_slide' === get_post_type(get_the_ID()) && ! is_main_query()){
causes the script to stop working. The query for my cpt to which this is supposed to apply is as follows:
function par2_slides_query () {
$args = array( 'post_type' => 'par2_slide');
$slides_loop = new WP_Query( $args );
while ( $slides_loop->have_posts() ) : $slides_loop->the_post();
echo '<li class="slide">';
the_content();
echo '</li>';
endwhile;
};
wpauto messes with the slide layout so I really need to filter the content for that particular post type to turn it off without turning it off for the instances of the_content on the rest of the page. It doesn't affect other pages, on the_content on the same page.
Re add the filter after your IF statement.
add_filter('the_content', 'wpautoop');
It removes it and returns the content IF par2_slide is the post type, and if it's not it adds the filter if it doesn't exist.

Wordpress: map existing page content instead of a copy

I have a page with several subpages in wordpress. The page should display the same content as the second subpage. When I edit the page, there is an option to copy the content from the subpage into it, but then I would have to maintain two instances of the text. Is there a possibility to map existing page content into a page? I'm using Wordpress.com so I cannot edit any files/links on the server.
You could use a shortcode that fetches the content of a page specified. In functions.php:
add_action( 'init', 'so20477735_init', 11 );
function so20477735_init()
{
add_shortcode( 'duplicate_page', 'so20477735_shortcode_callback' );
}
function so20477735_shortcode_callback( $atts, $content = null )
{
extract( shortcode_atts( array(
'page_id' => 0
), $atts ) );
$page_data = get_page( $page_id );
$return = '';
if( ! is_null( $page_data ) )
$return .= $page_data->post_content;
return $return;
}
Example usage:
[duplicate_page page_id="12"]
EDIT
I missed the fact you're using wp.com. You should be able to do something similar with the display posts shortcode:
http://en.support.wordpress.com/display-posts-shortcode/

Resources