What I currently have developed:
http://wordpress.test/hashtag/result/?hashtag=twerk
What I want to achieve:
http://wordpress.test/hashtag/twerk
I have made a custom plugin which currently reads the 'hashtag' (query string) and displays it through my custom shortcode.
/result/ is a static page with the custom shortcode [woink_hashtag_result]. This currently works as intended.
Here is what I've currently produced.
function woinkResult()
{
$return = '<p>' . get_query_var ('hashtag' ) . '</p>';
// Output needs to be return
return $return;
}
add_shortcode('woink_hashtag_result', 'woinkResult');
function pce_register_query_vars ( $vars ) {
$vars[] = 'hashtag';
return $vars;
}
add_filter ( 'query_vars', 'pce_register_query_vars' );
How can I make the url prettier like: http://wordpress.test/hashtag/twerk ?
Thanks if you have made it this far.
Related
I am trying have site url and admin url as shortcode in wordpres.
Code I am using is written below.
//Website URL shortcode [site_url]
add_action( 'init', function() {
add_shortcode( 'site_url', function( $atts = null, $content = null ) {
return site_url();
} );
} );
//Website admin URL shortcode [admin_url]
add_action( 'init', function() {
add_shortcode( 'admin_url', function( $atts = null, $content = null ) {
return admin_url();
} );
} );
Now the issue is, when I use [site_url] or [admin_url] it show url https//mysitename.com. Mean the link is without ":" in URL
I tried to use code below to replace https// with https:// but that one also not working...
//Replace text
function replace_text($my_text_replace) {
$my_text_replace = str_replace('https//', 'https://', $my_text_replace);
$my_text_replace = str_replace('https//https//', 'https://', $my_text_replace);
return $my_text_replace;
}
add_filter('the_content', 'replace_text');
Any suggestion please..
Thanks
I think you should check inside your database, in wp_options table the values of this 2 key: "home" and "siteurl". Since those functions actually read that value, go in the database and make sure 100% you didn't miss the double dots there
My website is built using Elementor using GeneratePress as default theme and I want to replace output final text with some values from the database. This plugin
Real-Time Find and Replace https://wordpress.org/plugins/real-time-find-and-replace/ is doing the replace functionality perfectly and it uses action:
//Handles find and replace for public pages
add_action( 'template_redirect', 'far_template_redirect' );
to replace text using code:
function far_ob_call( $buffer ) { // $buffer contains entire page
$far_settings = get_option( 'far_plugin_settings' );
if ( is_array( $far_settings['farfind'] ) ) {
foreach ( $far_settings['farfind'] as $key => $find ) {
if( isset( $far_settings['farregex'][$key] ) ) {
$buffer = preg_replace( $find, $far_settings['farreplace'][$key], $buffer );
} else {
$buffer = str_replace( $find, $far_settings['farreplace'][$key], $buffer );
}
}
}
return $buffer;
}
I can not use the plugin directly because it repalce text with text and I need to fetch data from database, so I have to make my own plugin. But, I found this blog: https://markjaquith.wordpress.com/2014/02/19/template_redirect-is-not-for-loading-templates/ that tells me to use a filter:
add_filter( 'template_include', 'my_callback' );
instead of the above action in plugin:
add_action( 'template_redirect', 'far_template_redirect' );
But the plugin is using the action.
What to use?
The plugin description says: "Set up find and replace rules that are executed AFTER a page is generated by WordPress, but BEFORE it is sent to a user's browser." this is what I exactly want. That is to replace text after page is generated and just before the page is sent to browser, but the plugin uses action for this, and other blogs suggest to use filter?
This is the code I am using to call my archive template, now the knowledgebase section works, the forums work, but all other pages throughout the website are now blank.
function kb_archive_template_function($arhive_template){
if(is_post_type_archive('knowledgebase')){
$theme_files = array('/templates/archive-knowledgebase.php');
$exists_in_theme = locate_template($theme_files, false);
if($exists_in_theme == ''){
return plugin_dir_path(__FILE__) . '/templates/archive-knowledgebase.php';
}
return $archive_template;
}
}
You can use this code ,instead of your code
function get_custom_post_type_template( $archive_template ) {
global $post;
if ( is_post_type_archive ( 'knowledgebase' ) ) {
$archive_template = plugin_dir_path(__FILE__) . '/templates/archive-knowledgebase.php';
}
return $archive_template;
}
add_filter( 'archive_template', 'get_custom_post_type_template' ) ;
Try that, then let me know the result. Thanks
my code is not working on custom page?
is aioseop_keywords hook wrong?
What is suggestion?
add_filter( 'aioseop_keywords', 'my_custom_keyword' );
function my_custom_keyword ( $keywords ) {
$keywords = '1,2,3,name,or,other';
return $keywords;
}
I am using the FeedWordPress plugin http://wordpress.org/extend/plugins/feedwordpress/ to pull posts from one site to another.
I have written a filter that after some help from Stack users successfully scans the $content and extracts the image URL into $new_content
define('FWPASTOPC_AUTHOR_NAME', 'radgeek');
add_filter(
/*hook=*/ 'syndicated_item_content',
/*function=*/ 'fwp_add_source_to_content',
/*order=*/ 10,
/*arguments=*/ 2
);
function fwp_add_source_to_content ($content, $post) {
// Use SyndicatedPost::author() to get author
// data in a convenient array
$content = $post->content();
// Authored by someone else
if( preg_match( '/<img[^>]+src\s*=\s*["\']?([^"\' ]+)[^>]*>/', $content, $matches ) ) {
$new_content .= 'URL IS '.$matches[0].'';
return $new_content;
}
else
{
}
}
What I wanted to do now was save this URL into a custom field instead of just returning it. Has anyone achieved anything similar?
So as I understand it, the plugin grabs content from external RSS feeds and creates them as posts in your website.
If this is the case, using your filter you should be able to grab the post ID within the $post variable.
So all you need is the add_post_meta() function to add a custom field to the specific post.
So including your code above it should look something like:
define('FWPASTOPC_AUTHOR_NAME', 'radgeek');
add_filter(
/*hook=*/ 'syndicated_item_content',
/*function=*/ 'fwp_add_source_to_content',
/*order=*/ 10,
/*arguments=*/ 2
);
function fwp_add_source_to_content ($content, $post) {
// Use SyndicatedPost::author() to get author
// data in a convenient array
$content = $post->content();
// Authored by someone else
if( preg_match( '/<img[^>]+src\s*=\s*["\']?([^"\' ]+)[^>]*>/', $content, $matches ) ) {
$new_content .= 'URL IS '.$matches[0].'';
//Add custom field with author info to post
add_post_meta($post->ID, 'post_author', $new_content);
return $new_content;
}
}