I use this function to obtain the title of post page in the content area:
function myshortcode_title( ){
return get_the_title();
}
add_shortcode( 'page_title', 'myshortcode_title' );
So, I have a plugin that when I use this shortcode below it read the text beetween the shortcode:
[responsivevoice voice="UK English Male"] Wonderful World [/responsivevoice]
So, what I'm doing and it's my question also is how can I put the "page title shortcode" within responsivevoice shortcode like this?
[responsivevoice voice="UK English Male"] [page_title] [/responsivevoice]
(It should get the title of the post page, but it doesn't work).
Choose one of the following options, and add the code snippet after:
add_shortcode( 'page_title', 'myshortcode_title' );
Option #1: [responsivevoice2]
add_shortcode( 'responsivevoice2', 'responsivevoice2' );
function responsivevoice2( $atts = array(), $content = '' ) {
if ( $content = do_shortcode( $content ) ) {
return RV_add_bblisten( $atts, $content );
}
return '';
}
Sample usage:
[responsivevoice2 voice="UK English Male"] [page_title] [/responsivevoice2]
This Shortcode allows you to use the [page_title] or any other Shortcodes in the
text to be spoken.
Option #2: [responsivevoice_page_title]
This Shortcode will always use the page title (or the title of the current post)
as the text to be spoken. With this Shortcode, you don't need the [page_title]
Shortcode anymore.
add_shortcode( 'responsivevoice_page_title', 'responsivevoice_page_title' );
function responsivevoice_page_title( $atts = array() ) {
if ( $page_title = get_the_title() ) {
return RV_add_bblisten( $atts, $page_title );
}
return '';
}
Sample usage:
[responsivevoice_page_title voice="UK English Male" /]
Related
I want to echo something after header tag in single pages.
I have a filter to add something before content.
function add_custom_meta_to_content($content) {
$queried_object = get_queried_object();
if ( $queried_object ) {
$post_id = $queried_object->ID;
}
$text = get_post_meta($post_id, 'textbox_wporg_meta_key', true);
if( is_single() ) {
$content = $text . '' . $content;
}
return $content;
}
add_filter( 'the_content','add_custom_meta_to_content' );
But Now I want add some data exactly after header tag in single pages by my plugin.
I don't want to edit theme codes.
How can I do that?
You wouldn't normally do this with the the_content filter. Almost all commercial themes would have a specific hook to insert additional code after the post title and before the main content. For instance, the Generatepress framework would enable you to hook into the generate_after_entry_title action hook and you would output additional code there.
I would like to know how to remove the word "archives" from a category or tag page title of a WordPress theme? Thank you!
Look at the official docs of get_the_archive_title(). You can modify the content through filter like below.
add_filter( 'get_the_archive_title', function ( $title ) {
if( is_category() ) {
$title = single_cat_title( '', false );
}
return $title;
});
I have a website that uses worpdress with catch box theme, and I want to change the 404 page title.
I looked for the "Nothing found for" sentence on the PHP files on the Editor but I did not find nothing.
I searched for the get_header(); method in editor to change the title but I did not find it.
see the title that I want to change
Have been already answered here: https://wordpress.stackexchange.com/questions/30873/how-to-change-404-page-title
Add the following to theme functions.php file
function theme_slug_filter_wp_title( $title ) {
if ( is_404() ) {
$title = 'ADD 404 TITLE TEXT HERE';
}
// You can do other filtering here, or
// just return $title
return $title;
}
// Hook into wp_title filter hook
add_filter( 'wp_title', 'theme_slug_filter_wp_title' );
You can use filter hook
function theme_slug_filter_wp_title( $title ) {
if ( is_404() ) {
$title = 'ADD 404 TEXT HERE';
}
return $title;
}
add_filter( 'wp_title', 'theme_slug_filter_wp_title' );
try this one for wordpress version 4.4+
file : function.php
function theme_slug_filter_wp_title($title_parts)
{
if (is_404()) {
$title_parts['title'] = 'My Custom Title Text';
}
return $title_parts;
}
add_filter('document_title_parts', 'theme_slug_filter_wp_title');
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/
Basically I need to remove the gallery shortcode from the Wordpress content, I'm using
echo preg_replace('/\[gallery ids=[^\]]+\]/', '', get_the_content() );
It is removing the gallery shortcode successfully, but also the paragraph tags which I need to keep. The idea is that I want to output everything in the content except the gallery.
You could use Wordpress strip_shortcode function.
Look at the example in the Codex.
You can create a filter that strips shortcodes:
function remove_shortcode_from($content) {
$content = strip_shortcodes( $content );
return $content;
}
and call it when you need (in your template):
add_filter('the_content', 'remove_shortcode_from');
the_content();
remove_filter('the_content', 'remove_shortcode_from')
EDIT 1
Another way to get that (and answering you comment) you can use Wordpress apply_filters function in the content after remove the undesirables shortcodes.
//within loop
$content = get_the_content();
$content = preg_replace('/\[gallery ids=[^\]]+\]/', '', $content );
$content = apply_filters('the_content', $content );
echo $content;
But I would not recommend to you to do that. I think forcing your site to modify the content of a post could make that hard to understanding. Maybe you should work with Wordpress Excerpt and avoid any problem.
A link that helped me
to remove a shortcode or a particular list of shortcode you can use this code.
global $remove_shortcode;
/**
* Strips and Removes shortcode if exists
* #global int $remove_shortcode
* #param type $shortcodes comma seprated string, array of shortcodes
* #return content || excerpt
*/
function dot1_strip_shortcode( $shortcodes ){
global $remove_shortcode;
if(empty($shortcodes)) return;
if(!is_array($shortcodes)){
$shortcodes = explode(',', $shortcodes);
}
foreach( $shortcodes as $shortcode ){
$shortcode = trim($shortcode);
if( shortcode_exists($shortcode) ){
remove_shortcode($shortcode);
}
$remove_shortcode[$shortcode] = 1;
}
add_filter( 'the_excerpt', 'strip_shortcode' );
add_filter( 'the_content', 'strip_shortcode' );
}
function strip_shortcode( $content) {
global $shortcode_tags, $remove_shortcode;
$stack = $shortcode_tags;
$shortcode_tags = $remove_shortcode;
$content = strip_shortcodes($content);
$shortcode_tags = $stack;
return $content;
}
dot1_strip_shortcode( 'gallery' );
Accepts single, comma seprated shortcode string or array of shortcodes.