Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Benjamin Denis

    (@rainbowgeek)

    Hi,

    these hooks are the correct ones but you will have to add a conditional tag.

    To target only a specific page template, use this one:

    https://developer.www.ads-software.com/reference/functions/is_page_template/

    Make sure to always return $html variable with these hooks.

    Thread Starter AlexS

    (@alexarium)

    Thank you Benjamin.

    Here’s what I got, but it doesn’t seem to be working.

    <?php
    function my_theme_enqueue_styles() {
    
        $parent_style = 'Divi-style';
    
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( 'child-style',
            get_stylesheet_directory_uri() . '/style.css',
            array( $parent_style ),
            wp_get_theme()->get('Version')
        );
    }
    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    
    // ADD DEFAULT SEOPRESS SETTINGS FOR LANDING PAGES
        function sp_titles_title($html) { 
    	if( is_page_template( 'landing_page.php' ) ){
    	$html = '%%post_title%%';
    	return $html;
    }
    add_filter('seopress_titles_title', 'sp_titles_title');
    }
    
    ?>

    Any ideas? Please keep in mind I’m not an expert in PHP so keep it simple ??

    • This reply was modified 4 years ago by AlexS.
    • This reply was modified 4 years ago by AlexS.
    Plugin Author Benjamin Denis

    (@rainbowgeek)

    function sp_titles_title($html) { 
        if( is_page_template( 'landing_page.php' ) ){
            $html = '%%post_title%%';
        }
        return $html;
    }
    add_filter('seopress_titles_title', 'sp_titles_title');

    Make sure the landing_page.php path is correct.

    If it’s located in subfolder of your theme like “page-templates” you have to add it like this:
    ‘page-templates/landing_page.php’

    Thread Starter AlexS

    (@alexarium)

    Thank you again Benjamin.
    I added the code and it… almost works.
    Here’s what happens to the page’s title:

    https://i.imgur.com/I3TiJSw.gif

    Essentially, %%post_title%% is displayed as is, instead of taking the post’s title. Another screenshot here, from within the post itself, if that will help you pinpoint the issue:
    https://i.imgur.com/ucFXUws.gif

    What I am trying to do is to have the actual page/post title show up instead of the text “%%post_title%%”.

    For example, if the page title is “Holidays in Paris” then in the page’s code it should show <title>Holidays in Paris</title> instead of <title>%%post_title%%</title>

    Thread Starter AlexS

    (@alexarium)

    Thanks again, it all works now

    • This reply was modified 4 years ago by AlexS.
    • This reply was modified 4 years ago by AlexS.
    Plugin Author Benjamin Denis

    (@rainbowgeek)

    Super!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How do I add meta title and description to page template?’ is closed to new replies.