I have generated these shortcodes.Whenever I am using these short codes in some particular place posts and pages are not showing in the right place.It comes at the beginning of the content.
Can anyone help me out here?
function __construct()
{
register_activation_hook( __FILE__, array($this,'my_auction_creator_activation' ));
add_action( 'add_meta_boxes', array($this,'my_auction_creator_custom_field' ));
add_action( 'save_post', array($this,'my_auction_creator_form_save' ));
add_shortcode('myauctioncreator_listing' , array($this,'ebay_listing' ));
add_shortcode('myauctioncreator_ads' , array($this,'ebay_ads' ));
add_shortcode('myauctioncreator_profile' , array($this,'ebay_profile' ));
add_shortcode('myauctioncreator_feedback' , array($this,'ebay_feedback' ));
}
To render the output of the shortcode, are you using print or echo?
If you are, you should be returning the content instead. Using print or echo will cause this issue.
i was getting exactly same issue as i was echo the contents
use like this
function shortcode_function()
{
ob_start();
//some echo or html code goes here
echo "<p>this is paragraph</p>";
return ob_get_clean();
}
Related
I am fluent in HTML and CSS but not so much in PHP. Any help would be appreciated.
I have a custom function in Wordpress as seen below:
function prefix_calculation_global_calculation_vars( $vars ) {
return array(
'setup_cost' => 200,
);
}
add_filter( 'pewc_calculation_global_calculation_vars', 'prefix_calculation_global_calculation_vars' );
Is it possible to call an Advanced Custom Fields (ACF) field or a Pods field and have the value inserted into the function above where the 200 is?
Providing get_the_ID() works you could try this:
function prefix_calculation_global_calculation_vars( $vars ) {
return array(
'setup_cost' => get_field('setup_cost', get_the_ID()),
);
}
add_filter( 'pewc_calculation_global_calculation_vars', 'prefix_calculation_global_calculation_vars' );
You would have to grab it via the $wpdb->postmeta table
<?php echo get_post_meta(get_the_ID(), 'setup_cost', TRUE); ?>
I don't want the customers to get linked to the myaccount-dashboard with the annoying Hello xy, from here you can blabla, when they click on "My Account".
Is there an endpoint for the my account dashboard? I didn't find it on the backend in woocommerce>Settings>Accounts...
What's working is: I set up a custom link under menu/navigation... called it "My Account" and set the link to /myaccount/downloads for example.
So, when customers are logged in and they click on My Account, they get redirected to Downloads.
I'm wondering, is there another way to get rid of the dashboard?
Or a redirect solution? Thanks.
Remove it using below function. change downloads to your requirement.
function custom_my_account_menu_items( $items ) {
unset($items['downloads']);
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'custom_my_account_menu_items' );
Looking more closely it seems like there are a handful of ways to do this. Take a look at the my-account.php template. You could override this, but I found that if you remove the woocommerce_account_content hook, you get a deprecation notice and WooCommerce thinks you have an outdated template and adds the content anyway.
Looking at the template you will see two hooks. The side menu navigation is added to the woocommerce_account_navigation and the content is added to woocommerce_account_content function. You can remove the defaults from their hooks and add back just the downloads content.
function so_41983566_remove_account_dadshboard(){
remove_action( 'woocommerce_account_navigation', 'woocommerce_account_navigation' );
remove_action( 'woocommerce_account_content', 'woocommerce_account_content' );
add_action( 'woocommerce_account_content', 'so_41983566_download_content' );
}
add_action( 'woocommerce_account_navigation', 'so_41983566_remove_account_dadshboard', 1 );
function so_41983566_download_content(){
do_action( 'woocommerce_account_downloads_endpoint' );
}
Or woocommerce_account_content() and woocommerce_account_navigation() are both pluggable functions and you can just define new versions in your theme/plugin.
This link explains everything:
https://github.com/woocommerce/woocommerce/wiki/Customising-account-page-tabs
First you need to create an endpoint:
function my_custom_endpoints() {
add_rewrite_endpoint( 'my-custom-endpoint', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'my_custom_endpoints' );
function my_custom_query_vars( $vars ) {
$vars[] = 'my-custom-endpoint';
return $vars;
}
add_filter( 'query_vars', 'my_custom_query_vars', 0 );
Then create the menu item:
function my_custom_my_account_menu_items( $items ) {
$logout = $items['customer-logout'];
unset( $items['customer-logout'] );
$items['my-custom-endpoint'] = __( 'My Custom Endpoint', 'woocommerce' );
$items['customer-logout'] = $logout;
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'my_custom_my_account_menu_items' );
Add content to the endpoint
function my_custom_endpoint_content() {
echo '<p>Hello World!</p>';
}
add_action( 'woocommerce_account_my-custom-endpoint_endpoint', 'my_custom_endpoint_content' );
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.
I am developing a plugin everything is going fine but there is a problem.
How can I hide or remove the comments box? I lost many hours but could not develop the right script. My current script is this:
add_filter( 'comments_template', 'remove_comments_template_on_pages', 11 );
function remove_comments_template_on_pages( $file ) {
if ( is_page() )
comments_template('', true);
}
I don't know how to develop this script. Any help could lead me to complete my plugin.
Add the below code to you functions.php file.
add_action('init', 'remove_page_feature');
function remove_page_feature() {
remove_post_type_support( 'page', 'comments' );
}
And now provide a check before the comments template is executed, as below:
if ( post_type_supports( 'page', 'comments' ); )
comments_template('', true);
}
Note: Using the above code will disable comments on pages.
I'm creating a meta box for my custom post type. There are multiple fields where I would like to use wysiwyg editor rather than <textarea>. Is is possible to add multiple editors to a meta box?
I would really appreciate your help!
Many thanks.
Dasha
Here is full code example:
add_action( 'add_meta_boxes', function() {
add_meta_box('html_myid_61_section', 'TITLEEEEE', 'my_output_function');
});
function my_output_function( $post ) {
$text= get_post_meta($post, 'SMTH_METANAME' , true );
wp_editor( htmlspecialchars($text), 'mettaabox_ID', $settings = array('textarea_name'=>'MyInputNAME') );
}
add_action( 'save_post', function($post_id) {
if (!empty($_POST['MyInputNAME'])) {
$datta=sanitize_text_field($_POST['MyInputNAME']);
update_post_meta($post_id, 'SMTH_METANAME', $datta );
}
});
P.S. MUST-Recommendation from my experience:
Forget adding custom codes, use Advanced Custom Fields, it's excellent and simplify your life.
http://codex.wordpress.org/Function_Reference/wp_editor was by far the easiest method I found, built into Wordpress since 3.3 (so upgrade ;-) )
// for custom post type
function wo_second_editor($post) {
echo "<h3>Write here your text for the blue box on the right:</h3>";
$content = get_post_meta($post->ID, 'wo_blue_box' , true ) ;
wp_editor( htmlspecialchars_decode($content), 'wo_blue_box', array("media_buttons" => false) );
}
add_action('edit_form_advanced', 'wo_second_editor');
function wo_save_postdata($post_id, $post, $update) {
//...
if (!empty($_POST['wo_blue_box'])) {
$data=htmlspecialchars($_POST['wo_blue_box']);
update_post_meta($post_id, 'wo_blue_box', $data );
}
}
add_action('save_post', 'wo_save_postdata');
// Theme:
<div class="blue">
<?php
$content = get_post_meta(get_the_ID(), 'wo_blue_box' , true );
$content = htmlspecialchars_decode($content);
$content = wpautop( $content );
echo $content;
?>
</div>
But you need to replace presentation with nl2br() function as textarea in custom templates have the toogle JS issue, that removes all your <P> and <br/> tags and therefore all line breaks.
You can use the wordpress default text editor in the metabox using
add_action( 'edit_page_form', 'my_second_editor' );
function my_second_editor() {
// get and set $content somehow...
wp_editor( $content, 'mysecondeditor' );
}
Try the custom field template plugin http://wordpress.org/extend/plugins/custom-field-template/
This did the trick for me:
http://www.farinspace.com/multiple-wordpress-wysiwyg-visual-editors/
It's basically creating your textarea with an id, then calling from js:
tinyMCE.execCommand('mceAddControl', false, 'your_textarea_id');
Hope it helps!
First install TinyMCE Advanced plugin.
Second add "theEditor" class to your textarea like this
<textarea class="theEditor" name="custom_meta_box"></textarea>
Thats it
;)
Nabeel