So I created this simple shortcode, which accepts a few params and it works as expected in the post page. I add a new post, implement the shortcode code and it all works great. But when I see the post in the homepage, it only shows the title not the content. Is there any wp code shortcode that I should implement in my shortcode in order to be able to see the content that the shortcode outputs, from the homepage/search results too?
function curr_func( $atts ) {
$a = shortcode_atts( array(
'am' => '',
'c1' => '',
'c2' => '',
), $atts );
$output = "The text I output";
return $output;
}
add_shortcode( 'fx', 'curr_func' );
This is the shortcode and I use it like
fx[ ...parameters ];
I have added this as a plugin. IS there any easy fix for this?
Related
When I integrate my CPT into the link search of the Classic Editor, it is at first displayed correctly.
But if there are more links in the list than can be displayed at the same time (overflow) and I then scroll up and down again, the list is updated by Wordpress via Ajax and my CPT links are appended again, so that the link list becomes longer and longer.
The default Wordpress links (post, page) on the other hand do not, even though my ID and the permalink in the $results array are unique.
There is nothing more than ID, title, permalink and info in the original $results array.
How can I prevent the appending?
add_filter('wp_link_query', array($this, 'wp_link_query'), 10, 2);
[...]
public function wp_link_query($results, $query) {
[...]
$results[] = array(
'ID' => $id,
'title' => $title,
'permalink' => $permalink,
'info' => $info
);
return $results;
}
The solution was to add the custom post type to the link query args first:
add_filter('wp_link_query_args', array($this, 'wp_link_query_args'), 10, 1);
[...]
public function wp_link_query_args($query) {
$query['post_type'][] = 'my_cpt';
return $query;
}
ยดยดยดยด
But you have to still use the 'wp_link_query' filter to add the "info" of the link popup table. Otherwise Wordpress outputs "Null" for the custom post type.
I am using a custom registration plugin with custom email template which can customized from admin side. For dynamic variables to put while trigger email, I have put [USER_NAME], [USER_PWD] in email template. But for the HTML tags, Characters like "<", ">" getting replaced by <, >. Which is causing problem.
Please note that the WordPress editor is being loaded from the custom plugin.
Inside custom plugin file I am loading the editor like below;
add_settings_field(
'email_field_body',
// use $args' label_for to populate the id inside the callback
__('Email Body', 'email'),
array($this, 'email_field_body'),
'email',
'email_section_developers',
[
'label_for' => 'email_field_body',
'class' => 'email_row',
'email_custom_data' => 'custom',
]
);
function email_field_body($args) {
wp_editor( isset( $this->options['email_field_body'] ) ?
esc_attr( $this->options['email_field_body']) : '' ,
'email_field_body', $settings =
array('textarea_name'=>"registration_email[email_field_body]") );
}
hade the same problem...
this comes by wordpress editor filters.
for updating the option use:
update_option( 'email_field_body', wp_kses_post( stripslashes ( $yourVariable ) ) );
Here is the documentation of the filter
Is there a way to check if a shortcode exist, including its 'id' attribute ?
For example, checking if the following shortcode is active on the website: [shortcode id="3268"]
Thanks in advance !
Try var_dump on the attributes within the Shortcode.
// var dump to show shortcode attributes are working
function bartag_func( $atts ) {
$att = shortcode_atts( array(
'foo' => 'something',
'bar' => 'something else',
), $atts );
var_dump($att);
}
add_shortcode( 'bartag', 'bartag_func' );
When you call the Shortcode ( [bartag] ) in this example - you will see the attributes default values (or the values you add to the Shortcode).
There is actually a shortcode API shortcode API in wordpress, allowing you to call functions and perform actions when the shortcode is present while displaying the page. If you want to check an entire website, you will have to code a plugin that goes thru all the content.
can any one help to solve a problem?
Just For example:
If I have one site wpnpl.com.np
I wannt to give access to the files of a plugin like if they type
wpnpl.com.np/npl they will access the features of the plugin
How to do this???Any Idea
First create plugin short code in your plugin core file
function bartag_func( $atts ) {
$atts = shortcode_atts( array(
'foo' => 'no foo',
'baz' => 'default baz'
), $atts, 'bartag' );
return "foo = {$atts['foo']}";
}
add_shortcode( 'bartag', 'bartag_func' );
After that create a page in wp-admin with slug npl and content with
[bartag foo="bar"]
I would like to create a file in the Wordpress theme, where i will add my own code, edit profile, show profile information, and perhaps an ability to insert posts / meta data programmatically.
So it needs to be www.mysite.com/profile.php or www.mysite.com/profile/
I do not want to use Buddy Press or any other plugin.
I know how the template system works, i do not want a page template.
It will probably be a class, later on, i do not want to change .htaccess file, and if i must i would appreciated filter function how to do this from functions.php
Basically just a simple .php file i can link to, located in theme root.
include('../../../wp-load.php');
and write any code i would like to.
Any creative solution that is not too "hacky" would be appreciated.
Spent around 2 days googling bashing my head on this, before i decided to ask question.
Thank you very much.
Ok, I managed to do this, took me 2 days to figure it out. Here is how I managed to do it:
Make a plugin folder.
In that plugin folder make 1x php file. so index.php
Ok so first thing we need to register plugin I did it like this, in your index.php paste
this code.
function activate_profile_plugin() {
add_option( 'Activated_Plugin', 'Plugin-Slug' );
/* activation code here */
}
register_activation_hook( __FILE__, 'activate_profile_plugin' );
Then we need a function when you register a plugin only once register profile pages.
function create_profile_page( $title, $slug, $post_type, $shortcode, $template = null ) {
//Check if the page with this name exists.
if(!get_page_by_title($title)) {
// if not :
$page_id = -1;
$page_id = wp_insert_post(
array(
'comment_status' => 'open',
'ping_status' => 'open',
'post_content' => $shortcode,
'post_author' => 1, // Administrator is creating the page
'post_title' => $title,
'post_name' => strtolower( $slug ),
'post_status' => 'publish',
'post_type' => strtolower( $post_type )
)
);
// If a template is specified in the function arguments, let's apply it
if( null != $template ) {
update_post_meta( get_the_ID(), '_wp_page_template', $template );
} // end if
return $page_id;
}
}
Ok so we created function which programatically register pages. It has 5 paramethers.
is Title
Slug
Post type
Shortcode.
Template
For the shortcode template you need to make a shortcode with the complete page output
and add it as a parameter to this function, so for registration page it will be a shortcode with the registration forms etc.
For example :
function registration_shortcode(){
echo 'Wellcome to Registration page';
}
add_shortcode('registration_output', 'registration_shortcode');
Next thing we need to call it once only when plugin loads.
so we do this :
function load_plugin() {
if ( is_admin() && get_option( 'Activated_Plugin' ) == 'Plugin-Slug' ) {
delete_option( 'Activated_Plugin' );
/* do stuff once right after activation */
// example: add_action( 'init', 'my_init_function' );
create_profile_page('Registration', 'registration', 'page', '[registration_output]');
create_profile_page('Profile', 'profile', 'page', '[profile_shortcode]');
create_profile_page('Profil Edit', 'profile-edit', 'page', '[edit_shortcode]');
}
}
add_action( 'admin_init', 'load_plugin' );
Ok so this will execute only once when plugin loads and it will create 3 Pages, which are Profile, Registration and Profile Edit.
And that's it, you have your front-end user profile blank pages, and you can write page output in shortcodes ,create more pages, put any forms or elements you like and create decent profile (which doesn't have any stuff you don't need in it like plugins. )
Hope this helps, it was painful for me to figure this out. Cheers!